In a shipping app that has worked correctly under iOS 5.X and supports all orientations, built against iOS 6 it always starts in portrait even when the ipad/simulator is in landscape).
I did add the new rotation methods
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0);
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
but that makes no difference.
Note we do not use a navigation controller as the root view controller. Otherwise the app rotates correctly after the initial problem.
The root view controller handles all the decision making for rotations and is added to the main window as
self.window.rootViewController = viewController;
I have all the rotations in the plist key set UISupportedInterfaceOrientations~ipad
Any ideas why the initial rotation is ignored?
Under 5.1 it calls shouldAutorotateToInterfaceOrientation and willRotateToInterfaceOrientation, etc. correctly but not under 6.0. If I build against 5.1 SDK then all is well.
After talking with Apple, they claim it is a bug in Xcode 4.5 on existing projects. Either you can create a new project and re-add everything (hard to do with a big project like ours). Or add you rotation logic something like this:
- (void)viewWillLayoutSubviews
{
if ( ! afterFirstTime )
{
[self handleRotationFor:self.interfaceOrientation];
afterFirstTime = YES;
}
}
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self handleRotationFor:toInterfaceOrientation];
}
on your root view controller. I got this answer right before their break Thanksgiving week so it might be a little sketchy, but this code does work.
If your application support portrait view, as MusiGenesis said; "iPad apps always start in portrait (even if the device is landscape) in iOS 5 as well."
But i found a solution to start in device orientation.
You can set the initial rotation in the root ViewController, after viewDidLoad function as below.
The code seems to be pointless but it works.
No need to handle portrait rotation.
-(void)viewDidLoad {
[super viewDidLoad];
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) {
[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationLandscapeLeft];
}
else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) {
[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationLandscapeRight];
}
}
Regards.