How to force a UIViewController to Portrait orientation in iOS 6

后端 未结 16 1590
别那么骄傲
别那么骄傲 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:44

    So I ran into the same problem when displaying portrait only modal views. Normally, I'd create a UINavigationController, set the viewController as the rootViewController, then display the UINavigationController as a modal view. But with iOS 6, the viewController will now ask the navigationController for its supported interface orientations (which, by default, is now all for iPad and everything but upside down for iPhone).

    Solution: I had to subclass UINavigationController and override the autorotation methods. Kind of lame.

    - (BOOL)shouldAutorotate {
        return NO;
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskPortrait;
    }
    // pre-iOS 6 support 
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
        return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
    }
    

提交回复
热议问题