iOS 6 SupportedOrientations with UINavigationController
You probably already know that -shouldAutorotateToInterfaceOrientation had been deprecated in iOS 6 and we were told to move to -shouldAutorotate and -supportedInterfaceOrientations, but me and apparently many others on SO and on the Apple forums were having trouble if the rootViewController in the AppDelegate was anything besides a UIViewController.
So here’s my solution that could probably work if you subclassed UITabBarController also.
My subclassed UINavigationController that is Orientation Aware of it’s top-most ViewController.
(I will provide the class files at the bottom of the post)
So First of all you’ll override these 2 methods so that the top viewcontroller of the hierarchy will take control of the orientation.
-(NSUInteger)supportedInterfaceOrientations { return [self.topViewController supportedInterfaceOrientations]; } -(BOOL)shouldAutorotate { return YES; }
Now whichever ViewController’s you don’t want to rotate add these lines of code.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } -(BOOL)shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }
And for any ViewController that you do want to be able to rotate and code like this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; } -(BOOL)shouldAutorotate { return YES; }
Here are the class files for the Orientation-aware UINavigationcontroller
-
phoenix-hurricane likes this
-
nicedexter reblogged this from shabzcode
-
webcoderph reblogged this from shabzcode
-
cocoamex reblogged this from shabzcode
-
cocoamex likes this
-
napolux likes this
-
amirsaam likes this
-
shabzcode posted this