Force & then Lock Orientation UIViewController added to UINavigationViewController (Nav Controller supports all orientations)

I believe the title says what I'm trying to implement; Below I describe what I am trying to achieve, and how I tried to do the same, but with partial success.

VC-ViewController NC-NavigationController

I installed NC as a RootVC application. Written category for NC. Overriding supported interfaces and attributes.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; UINavigationController *appNavController = [[UINavigationController alloc]init]; appNavController.view.backgroundColor = [[UIColor redColor]colorWithAlphaComponent:0.5]; self.window.rootViewController = appNavController; [self.window addSubview:appNavController.view]; FirstViewController *_firstViewController = [[FirstViewController alloc]init]; [appNavController pushViewController:_firstViewController animated:YES]; [_firstViewController release]; return YES; } 

Category for UINavigationController // UINavigationController.m

 @implementation UINavigationController(Rotation) -(BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; } -(NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; } -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; } 

I add FirstVC that supports all orientations, and everything works great here.

 //FirstViewControlle.m -(BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } 

From the first VC, I add another VC (SecondVC) to the NC using pushViewController.

Case 1: When the orientation of the first VC is Landscape and SecondVC is clicked on NC, rotation is blocked and SecondVC is loaded in landscape orientation.

Case 2: now the problem occurs when firstVC is in portrait mode and SecondVC is pressed on the CNC, rotation is blocked (as Toutorotate should be set to NO), but the second VC is loaded in portrait mode. Here I cannot force the orientation to be set, although the InterfaceOrientations supported for secondVC are set to UIInterfaceOrientationMaskLandscape. You need to load the second VC in Landscape regardless of the orientation of the NC and lock it in Landscape while the secondVC is being viewed.

//SecondViewControlle.m

 -(BOOL)shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } 

I mentioned the following Q & A Forced Portrait ... when implementing the above code.

All suggestions and solutions are welcome; Thank you in advance.

+1
iphone uiviewcontroller ios6 ipad uinavigationcontroller
Nov 10
source share

No one has answered this question yet.

See similar questions:

83
How to force UIViewController orientation to portrait orientation in iOS 6

or similar:

eleven
iOS 7+ Dismiss Modal View Controller and Force Portrait Orientation
four
preferInterfaceOrientationForPresentation should return a supported interface orientation (iOS 6)
2
UIViewController Orientation Issues in iPad
2
can iOS 6 block different orientations for different view controllers in UITabBarController?
2
IOS 6.0 rotation issues
2
Changing the orientation of the iPhone power device in portrait mode after rejecting custom navigation
one
ios 6.0 - Landscape not working - subclasses of UINavigationController never calls toAutorotate method
one
Screen orientation lock for single controller when UITabBar in iOS 5 and 6
one
Why doesn't the UINavigationController change orientation when I click on a controller with different supported orientations?
0
shouldAutorotateToInterfaceOrientation not working



All Articles