Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually route willRotateToInterfaceOrientation calls

I have multiple UIViewControllers and their views are nested within each other by using add subviews. I just got all of my views automatically changing orientation, except one. The one right at the end of the stack. I have also realized that the willRotateToInterfaceOrientation method does not propagate down to subviews controllers. Whats the best way to handle this? Should I try manually route the calls to subviews?

The end Controller thats not rotating was taken from a sample photo viewer app PhotoViewController and that relies on the willRotateToInterfaceOrientation method being called.

Any help would be appreciated.

like image 528
Craigt Avatar asked Dec 03 '25 16:12

Craigt


2 Answers

For iOS 4.3 and prior, routing the calls for willRotateToInterfaceOrientation (and other such methods) is completely fine practice. The issue is that there was no concept of view controller's being sub-view-controllers of other view controllers.

In iOS 5, the concept of container view controllers was introduced (of which it turns out that UINavigationController and UITabBarController were special "container view controllers" all along - notice that these view controllers already route these methods to your own view controllers!). The concept of a container view controller formalizes this idea of routing methods such as willRotateToInterfaceOrientation from parent view controllers to child view controllers.

You should check out the "Implementing a Container View Controller" section of the "UIViewController" class reference document. iOS5 is currently in developer preview, so you need to be a registered iOS developer to access this. From iOS5 onwards, this will be the preferred way of going about the problem you've described.

like image 175
James Bedford Avatar answered Dec 05 '25 06:12

James Bedford


Before iOS 5 you have to route all 4 of the major rotation methods down. This includes

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration;
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

To implement this type of containment properly, you will also need to route the UIView lifecycle methods:

- (void)viewDidLoad;
- (void)viewDidUnload;
- (void)viewWillAppear:(BOOL)animated;
- (void)viewDidAppear:(BOOL)animated;
- (void)viewWillDisappear:(BOOL)animated; 
- (void)viewDidDisappear:(BOOL)animated;
like image 38
Christopher A Avatar answered Dec 05 '25 07:12

Christopher A



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!