Multiple UIViewControllers don't autorotate correctly
Multiple UIViewControllers don't autorotate correctly
- Subject: Multiple UIViewControllers don't autorotate correctly
- From: Gwynne Raskind <email@hidden>
- Date: Thu, 7 May 2009 07:36:25 -0400
Disclaimer: As far as my understanding goes, the iPhone SDK NDA has
been lifted and I'm free to ask this question here. If for some crazy
reason this isn't true, please just delete this e-mail.
My iPhone application has one UIViewController for each piece of its
interface. Each such controller is connected to a view which takes up
the entire screen. My application runs exclusively in Landscape mode;
all my view controllers implement:
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Further, I run with the status bar hidden, and in -
applicationDidFinishLaunching: my app delegate calls:
[application setStatusBarHidden:YES animated:NO];
I have a method in my main coordinating controller which looks like
this:
- (void)switchToController:(UIViewController *)newController
{
UIWindow *window = [UIApplication
sharedApplication].keyWindow;
// Could also get the window from [UIApplication
sharedApplication].delegate.window
[self.currentController.view removeFromSuperview];
self.currentController = newController;
[window addSubview:newController.view];
}
This method is called at various times in response to various user
actions. The currentController property has the retain storage type
and newController is correctly released (usually autoreleased) by the
caller; I'm quite certain there's no memory management issue involved
in this.
When this is called at application startup by the UIApplication
delegate (from -applicationDidFinishLaunching:, immediately after
making the window key), everything works beautifully. The first view
controller picks up the Landscape orientation and displays correctly.
Unfortunately, any subsequent view controller I pass to this method
displays incorrectly. Specifically, the view is rotated as if for
Portrait orientation, and is vertically offset halfway off the top of
the screen. Any modal controllers opened by the controller are also
wrong.
The problem corrects itself when the device is turned around enough to
trigger an autorotation.
The two controllers in question - both the working one and the first
broken one - are set up with practically identical nibs: same
simulated interface metrics, same attributes in pretty much every way
in fact. They both override the same UIViewController methods and both
call super's implementations in the same places. I can't find any
difference between them to account for this error.
So far I've been able to solve the problem using the SPI [UIWindow
forceUpdateInterfaceOrientation], but obviously this is not a real
solution! Not to mention it causes a user-visible rotation of the
interface from being wrong to being right, so even if it were public
it'd still be ugly.
Can anyone suggest where I might be doing something wrong, or how to
correct the problem?
(As a side note that may be related, I used to have the
UIInterfaceOrientation key in my application's plist, but that caused
the status bar to pop up in portrait mode and get stuck that way!
Taking the key out solved that issue.)
-- Gwynne, Daughter of the Code
"This whole world is an asylum for the incurable."
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden