iosuiviewcontrolleruiinterfaceorientation

Support Landscape for one UIViewController and Portrait for Others in UINavigationController Stack


I have 4 UIViewControllers -- Named as ControllerA,ControllerB,ControllerC,ControllerD.

Where ControllerA is RootViewController in UINavigationStack.

ControllerA *ca = [[ControllerA alloc]initWithNibName:@"ControllerA" bundle:nil];
UINavigationController *nv = [[UINavigationController alloc]initWithRootViewController:ca];
self.window.rootViewController = nv;

After this is pushed ControllerB ,they are both in potrait,but problem comes here i want controllerC in landscape.

I have gone through many Codes,but any satisfactory or working solution but i did manage to rotate it by transforming view along angle --

[[UIApplication sharedApplication]]setStatusBarOrientation:UIInterfaceOrientationLandscapeRight
animated:YES];
self.view.transform = CGAffineTransformMakeRotation(M_PI/2);

But now i want to present modally ControllerD on controllerC and it doesNot coming in landscape if it does by some rotation , it will disturb all other viewcontroller transform .

After doing so much , i came back on same problem of making ControllerC in landscape by some documented method.


Solution

  • For Portrait Mode VC,

    #pragma mark iOS 5 Orientation Support
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
         return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
    
    #pragma mark iOS 6 Orientation Support
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    

    For Landscape mode VC,

    #pragma mark - iOS 5.0 and up Rotation Methods
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
        return UIInterfaceOrientationMaskLandscape;
    
    }
    
    #pragma mark - iOS 6.0 and up Rotation Methods
    
    - (NSUInteger)supportedInterfaceOrientations;
    {
        return UIInterfaceOrientationMaskLandscape;
    }