iOS 7: How to allow only portrait orientation for VC

3 Solutions Collect From Internet About “iOS 7: How to allow only portrait orientation for VC”

If you want different orientation for view controllers, In AppDelegate add this method –

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;

    if(self.window.rootViewController){
        UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
        orientations = [presentedViewController supportedInterfaceOrientations];
    }

    return orientations;
}

and in your ViewController –

-(BOOL)shouldAutorotate{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations{
    return (UIInterfaceOrientationMaskAll);//Change this according to your need
}

Hope this will help.

enter image description here
Go to your project -> General -> Device Orientation and just select only portrait in General settings.

You have

UINavigationController  -- UIViewController1
                        -- UIViewController2

You have to subclass UINavigationController and implement shouldAutorotate and supportedInterfaceOrientations. In UIViewController1,2 allow to rotate whatever orientations which you want.