Hap*_*Pig 4 iphone uiviewcontroller autorotate modalviewcontroller ios
模态UIViewController的父级自动旋转,但是当模态VC启动时,我只希望它以纵向显示而不能旋转.我试过简单地从shouldAutorotate模态VC中返回NO ,但没有快乐.支持iOS 5+.
任何帮助非常感谢.
小智 11
基本上,如果你在任何容器控制器(即UINavigationController)上呈现模态控制器,它具有自动旋转方法默认返回YES.因此,您必须为您的UINavigation Controller和Deprecate Autorotation创建子类.
对于iOS 5使用方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationPortrait) : self.enableRotations;
}
Run Code Online (Sandbox Code Playgroud)
对于iOS 6:
- (NSUInteger)supportedInterfaceOrientations {
switch ([UIDevice currentDevice].userInterfaceIdiom) {
case UIUserInterfaceIdiomPad: return UIInterfaceOrientationMaskAll;
case UIUserInterfaceIdiomPhone: return UIInterfaceOrientationMaskPortrait;
}
}
- (BOOL)shouldAutorotate {
return NO;
}
Run Code Online (Sandbox Code Playgroud)