强制将视图控制器仅设置为纵向 [英] Force view controller to portrait only
本文介绍了强制将视图控制器仅设置为纵向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我试图将视图控制器强制设置为仅纵向.我正在使用下面的代码,但实际上没有任何反应.我仍然可以像人像一样看到风景的屏幕吗?
In my application I am trying to force a view controller to be portrait only. I am using the code below but nothing is really happening. I am still able to see the screen in landscape as in portrait?
我在项目设置中启用了横向(左右)肖像.
I have enabled landscape (left/right), portrait in my project settings.
我做错了什么?
ViewController.m
ViewController.m
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
推荐答案
如果VC嵌入在导航或标签栏控制器中,则需要在该控制器上创建一个类别.这是一个允许导航控制器以各种方式旋转的示例:
If you VC is embedded in a navigation or tab bar controller you need to create a category on that controller. This is an example that allow navigation controller rotate in all ways:
#import "UINavigationController+RotationAll.h"
@implementation UINavigationController (RotationAll)
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
@end
这篇关于强制将视图控制器仅设置为纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文