I just had to upgrade the iOS 5 application to iOS 6 and, of course, I came across interface orientation problems. Now I already know that everything has changed, and I even know what has changed, but I can not deal with it on my own.
My application consists of several view controllers that fall into the navigation controller. It is assumed that all viewcontrollers are in landscape orientation, with the exception of one, which should be in portrait orientation. In iOS 5, everything worked fine, but now one controller in portrait mode is also displayed in landscape mode and, of course, is distorted.
My iOS 5 code looked like this:
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 have learned about the changes in iOS 6, I implemented
AppDelegate: (allowing all orientations, as in plist)
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; }
Viewcontroller in landscape mode: (orientation restriction in landscape mode)
- (NSUInteger) supportedInterfaceOrientations{ return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight } -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; } - (BOOL)shouldAutorotate{ return YES; }
Viewcontroller in portrait mode: (orientation restriction in 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 that it works even less than before. Firstly, the landscape view controllers do not remain in landscape mode, they rotate freely in all directions, this, of course, is not what I wanted. Secondly, portrait view manager will work with
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
After some trial and error, I can only block all the controllers in landscape mode via the plist / appdelegate file, which, of course, makes the portrait manager also work in landscape mode. On the other hand, I can control the portrait mode controller in the correct orientation, but it will also turn the landscape mode controllers into portrait mode. I can't seem to get both to work.
Any ideas?