IOS6 interface orientation broken

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?

+4
source share
2 answers

Ok, I fixed it.

I made a category for UINavigationController

 @implementation UINavigationController (Rotation_IOS6) -(BOOL)shouldAutorotate { return [self.topViewController shouldAutorotate]; } -(NSUInteger)supportedInterfaceOrientations { return [self.topViewController supportedInterfaceOrientations]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [self.topViewController preferredInterfaceOrientationForPresentation]; } @end 

to redirect view controller values ​​to the navigation controller ...

I also had to replace presentModalViewController with currentViewController since the first one is deprecated.

btw, yes there is a typo in my appdelegate ... that's right.

 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown; } 
+7
source

Just noticed that your UIInterfaceOrientationMaskLandscapeLeft is written twice in the appdelegate LandscapeRight is missing If its a fair typo and still encounters a problem after fixing

I found only rootViewControllers - (BOOL) shouldAutorotate; get a call. Here ur rootViewController is NavigationController. And for push-viewController this is not called so that you can select orientation support only for push-view from the navControllers methods. After working for me, for my navControllers clicked viewController
Override UINavigationControllers Methods

 - (BOOL)shouldAutorotate; - (NSUInteger) supportedInterfaceOrientations; 

The code will be something like this for u

 @implementaion UINavigationController(Rotation) - (BOOL)shouldAutorotate { return YES; } - (NSUInteger) supportedInterfaceOrientations { NSArray *viewsArray = [self viewController]//stack of pushed controller NSUInteger orientationToReturn = assignAllMask; for(UIViewController *temp in viewsArray) { if([temp isKindOfClass:MyOnlyLandscapeViewController] == YES ) { orientationToReturn = assignLandscapeMask; break; } else if([temp isKindOfClass:MyOnlyPortraitViewController] == YES ) { orientationToReturn = assignPortraitMask; break; } } return orientationToReturn; } @end 
0
source

Source: https://habr.com/ru/post/1438692/


All Articles