The UIViewController
class provides the fundamental view-management model for iPhone applications. It provides automatic support for rotating the views of the view controller in response to changes to the orientation of the device. If the autoresizing properties of your view and subviews are properly configured, this behavior is essentially free. Your view controller may not rotate in certain situations if:
- The view controller does not implement this delegate method:
Even if- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
is implemented, you should make sure it returns YES for all the orientations you wish to support. To support all orientations, simply always return YES.shouldAutorotateToInterfaceOrientation
- The view controller's
property is embedded insideUIView
UIWindow
but alongside an additional view controller.
You may find a situation where
is called once at startup for a given view controller but is never called again when the device is rotated. Because view controllers are tightly bound to the views they manage, they are also part of the responder chain used to handle events. View controllers are themselves descendants of theshouldAutorotateToInterfaceOrientation
class and are inserted into the responder chain between the managed view and its superview. So it is common practice to have one primary view controller in your application as part of the responder chain. You would typically add one primary view controller such as aUIResponder
,UINavigationController
or a genericUITabBarController
to yourUIViewController
. For example, this is done by calling:UIWindow
If you add an additional view controller's[myWindow addSubview:primaryViewController.view];
property toUIView
(at the same level as your primary view controller) via the following:UIWindow
this additional view controller will not receive rotation events and will never rotate. Only the first view controller added to[myWindow addSubview:anotherController.view];
UIWindow
will rotate.
Note: You may add one view controller's
property as a subview to another view controller. In doing so, both views will rotate but the parent view controller remains in charge of determining the supported orientations via itsUIView
shouldAutorotateToInterfaceOrientation
method.
Note: Keep in mind that
andUINavigationController
have the capability to manage a "stack" or "list" of view controllers on their own.UITabBarController
- You have added your view controller's
UIView
as a subview, but prematurely released it soon after.UIWindow
will retain that view, but not the view controller itself. You must not release it prematurely. Declare it as a "retainable" property in yourUIWindow
UIApplicationDelegate
subclass.
Note:
UINavigationController
retain your view controllers, so you can release them once they have been added.UITabBarController