just had to update an iOS 5 App to iOS 6 and of course stumbled over the interface orientation issues. I now already know that things changed and I even know what changed, still I can't seem to manage it on my own.
My App consists of several viewcontrollers, which get pushed onto a navigationcontroller. All viewcontrollers are supposed to be in landscape orientation, except for one, which should be in portrait orientation. In iOS 5 everything worked fine, but now the one controller in portrait mode is also shown in landscape mode and of course gets distorted.
My iOS 5 code looked like that:
Viewcontroller in landscape mode:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}
Viewcontroller in portrait mode:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationPortrait) || (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);
}
Now that I found out about the changes in iOS 6 I implemented
AppDelegate: (allowing all orientations, like in the plist)
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
Viewcontroller in landscape mode: (restricting orientations to landscape mode)
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate{
return YES;
}
Viewcontroller in portrait mode: (restricting orientations to portrait mode)
- (NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
- (BOOL)shouldAutorotate {
return YES;
}
From my understanding this should work, but the truth is it works even less than before. First, the landscape mode viewcontrollers don't stay in landscape mode, they rotate freely in all directions, this is of course not what I wanted. Second, the viewcontroller in portrait mode will crash with
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
After some trial and error I only seem able to lock all controllers to landscape mode, via the plist file/appdelegate, which of course forces the portrait mode controller also into landscape mode. On the other hand I can manage to have the portrait mode controller in proper orientation, but this will also rotate the landscape mode controllers into portrait mode. I can't seem to get both to work.
Any ideas?