IOS 6 - Landscape rotation of the navigation controller for some views, while others are only portrait

I am creating an application that will be "Portrait" only for the main types (both normal and inverted). I set this parameter in Project Settings / Plist and everything works fine. However, I have a few modal representations that do things like image / video display, and I want them to be able to rotate to all orientations.

I tried adding a category for the UINavigationController, but no luck. I also added to the viewController, which calls the modal code below:

-(BOOL)shouldAutomaticallyForwardAppearanceMethods{ return NO; } -(BOOL)shouldAutomaticallyForwardRotationMethods{ return NO; } 

I added the code below to the modal viewControllers, which I want to allow for all orientations:

 - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } 

What am I missing? Any suggestions?

+3
ios rotation modal-dialog uiinterfaceorientation
Feb 20
source share
2 answers

In iOS 6, rotation processing has changed. There are several approaches to this problem. First, in the plist, turn on all orientations except portrait upside down.

Then you can use one of the following solutions:

  • Use a subclass of UINavigationController that only allows rotation for portraiture.
  • For all controllers, indicate which rotations they support.
  • You can override the method in the application deletion. Since this delegate method is called whenever the orientation changes or a new view controller is created, you can use it to temporarily enable / disable the terrain display for your application:

     // In AppDelegate.h: @property (nonatomic) BOOL portraitOnly; // In AppDelegate.m: - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return _portraitOnly ? UIInterfaceOrientationMaskPortrait : UIInterfaceOrientationMaskAllButUpsideDown; } // to switch to portrait only: ((AppDelegate *)[UIApplication sharedApplication].delegate).portraitOnly = YES; // to switch to allowing landscape orientations: ((AppDelegate *)[UIApplication sharedApplication].delegate).portraitOnly = NO; 
+3
Apr 25 '13 at 10:44
source share

You need to enable rotation for viewControllers, which are the ancestors in the hierarchy in your build settings (to allow the VC lower in the hierarchy to be able to rotate if they want to). Then return the correct logic from shouldAutoRotate , supportedInterfaceOrientations and willAnimateRotationToInterfaceOrientation to each viewController.

-Remove NO from shouldAutoRotate to view shouldAutoRotate that do not move at all.

-And also return YES from shouldAutoRotate and return the orientations valid in this VC from supportedInterfaceOrientations

-Use willAnimateRotationToInterfaceOrientation to perform the last cleanup or change of data that needs to be done before a new orientation appears.

Feel free to let me know if you have a problem. Hope this helps!

+1
Feb 20 '13 at 20:47
source share



All Articles