First of all, you need to subclass your Navigation or TabController.
- Create a new .h and .m files and name it as CustomNavigationController.h and .m respectively.Now add these methods to .m file.
- (BOOL)shouldAutorotate{ return self.topViewController.shouldAutorotate; } - (NSUInteger)supportedInterfaceOrientations{ return self.topViewController.supportedInterfaceOrientations; }
- Now create a CustomNavigationControllerobject in AppDelegate class and this in method, application:DidFinishLaunchingWithOptions: set your newly created navigation controller object as rootViewController for window object. _window.rootViewController = _navController;
- Now in your ViewController class, if you want your view to rotate, write this.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } -(NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskAllButUpsideDown; } -(BOOL)shouldAutorotate{ return YES; }
- If you do not want your ViewController's view to rotate on device orientation, do this.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return (interfaceOrientation == UIInterfaceOrientationPortrait); } -(BOOL)shouldAutorotate{ return NO; } -(NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; }