我使用storyboard创建UIViewController并将其链接到UIViewController类。
我想让我的UIViewController只支持纵向方向,我试过吹代码,但似乎它不起作用。我的UIViewController仍然旋转。
我需要改变storyboard中的任何属性吗?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
shouldAutorotateToInterfaceOrientation
在iOS6中已弃用,您应该使用shouldAutoRotate
&supportedInterfaceOrientations
.
在你的viewController中试试这样。
- (BOOL)shouldAutorotate {
return NO;
}
- (BOOL)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
我在这里找到了答案:
我的uiviewcontroller是由UINavigationController管理的,它在iOS 6中控制它的方向:
现在,iOS容器(如UINavigationController)不会咨询它们的子容器来决定它们是否应该自动旋转。默认情况下,应用程序和视图控制器支持的界面方向被设置为iPad习惯用法的UIInterfaceOrientationMaskAll和iPhone习惯用法的UIInterfaceOrientationMaskAllButUpsideDown。
我必须用新的shouldAutorotate和supportedInterfaceOrientations
子类化UINavigationController我看到其他帖子更喜欢添加类别而不是子类。但是对我来说,子类化工作得很好。