How to force a UIViewController to Portrait orientation in iOS 6

后端 未结 16 1523
别那么骄傲
别那么骄傲 2020-11-22 06:03

As the ShouldAutorotateToInterfaceOrientation is deprecated in iOS 6 and I used that to force a particular view to portrait only, what is the c

16条回答
  •  执笔经年
    2020-11-22 06:43

    The best way for iOS6 specifically is noted in "iOS6 By Tutorials" by the Ray Wenderlich team - http://www.raywenderlich.com/ and is better than subclassing UINavigationController for most cases.

    I'm using iOS6 with a storyboard that includes a UINavigationController set as the initial view controller.

    //AppDelegate.m - this method is not available pre-iOS6 unfortunately

    - (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;
    }
    

    //MyViewController.m - return whatever orientations you want to support for each UIViewController

    - (NSUInteger)supportedInterfaceOrientations{
        return UIInterfaceOrientationMaskPortrait;
    }
    

提交回复
热议问题