didRotateFromInterfaceOrientation not firing when rotating?
Solution 1
Well, I never did figure out why the events were not firing, but I did figure out a workaround:
In the two UISplitViewController
delegate methods, splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
and splitViewController:willShowViewController:invalidatingBarButtonItem:
, I'm detecting whether or not my view is visible, and then doing my rotation logic here.
Solution 2
If your UIViewController is a child in some root view then IB does not add it as a child controller to the root controller by default. The easiest way to address this is to modify your root controller:
- (void)viewDidLoad
{
[super viewDidLoad];
[self addChildViewController:(UIViewController*) self.yourChildController];
}
This should do the trick. Now your child controller will be receiving both:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
and
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
messages.
DOOManiac
Just some guy who does PHP, JS, & MySQL web development.
Updated on June 12, 2022Comments
-
DOOManiac almost 2 years
Possible Duplicate:
ViewController not responding to didRotateFromInterfaceOrientationI'm having trouble with the didRotateFromInterfaceOrientation method not firing in one of my viewcontroller subclasses.
I have an iPad app w/ UISplitViewController as the main view. On the Detail side, I'm using a "hidden" (no toolbar,navbar) navigation controller for lazy view switching. The ViewController I'm wanting to catch didRotateFromInterfaceOrientation on is two levels deep in the navcontroller hierarchy. (None of this should make a difference, but I'm including this info in case there's some particular case that I don't know about)
I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } // This doesn't work. :( - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { NSLog(@"Rotate Go!"); }
The view rotates just fine, but didRotateFromInterfaceOrientation never fires.
Any idea what I'm missing?
-
Felipe Sabino about 13 yearsDo you have a uitabbar? Because if you are, you should create a uitabbar class and implement the "shouldAutorotateToInterfaceOrientation" at this class as well, so that all other controllers receive the rotation message.
-
DOOManiac about 13 yearsNope. I'm using a UISplitViewController, with a UIToolbar and UINavigationController (with the toolbar hidden, so different views share the other toolbar). But no UITabBar...
-
Felipe Sabino about 13 yearsAccording to apple, your UISplitViewController must be the root view in your application window. You can experience some weirdness if thatbis not the case. Check this SO thread stackoverflow.com/questions/2734016/…
-
DOOManiac about 13 yearsMy
UISplitViewController
is the root view of the window. I'm making sure to return YES toshouldAutorotateToInterfaceOrientation
from all of my subviews. The actual rotation works fine, its just thatdidRotateFromInterfaceOrientation
is never called. -
Felipe Sabino about 13 yearsSo, just a couple more question just to make it more clear. Are your controller extending any class other than
UIViewController
? Are you pushing yourUIViewController
or just adding the controller view as a subview of another controller? your are returning YES atshouldAutorotateToInterfaceOrientation
, but is this method really getting called when you rotate or just thedidRotateFromInterfaceOrientation
? -
DOOManiac about 13 yearsI have a
DetailViewController
(subclass ofUIViewController
) as the Detail side of theUISplitViewController
. Rather than swapping out detail views, which gave me problems, I'm taking the lazy way out by having aUINavigationController
onDetailViewController
, with both the toolbar and navigation bar hidden. I'm pushing my other classes (which are allUIViewController
subclasses with their own XIBs) onto the UINavigation stack to handle all changing of the detail views. -
DOOManiac about 13 years(continued) I am definitely returning YES to
shouldAutorotateToInterfaceOrientation
in all subclasses, as they rotate just fine. ButdidRotateFromInterfaceOrientation
never fires. :(
-
-
cberkley about 12 yearsThanks! This just fixed a problem that I had with UISplitViewController not getting rotational events.