ios - 我怎样才能为一个 viewController iOS 禁用横向

标签 ios orientation

我的项目有 UITabbar、UınavigationBar 和 UIViewContoller。

-UITabbar
 —UINavigationController
   —UIViewController

问题:我怎样才能横向禁用一个viewController?我只想纵向 View ,但只有一个 View 。

最佳答案

<罢工> disable autorotate on a single UIViewController in iOS6

<罢工>

将此添加到您的应用委托(delegate)

- (NSUInteger) application:(UIApplication *)application     supportedInterfaceOrientationsForWindow:(UIWindow *)window {

if ([[window.rootViewController presentedViewController] isKindOfClass:[YourViewController class]])
    return UIInterfaceOrientationMaskPortrait;
else
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

<罢工> 编辑 2

我最近发现了这一点,它对我来说效果很好。将此代码添加到您的 View Controller

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

然后在你的 viewWillAppear 添加

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    ///Disable orientation changes
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}

关于ios - 我怎样才能为一个 viewController iOS 禁用横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26830458/

相关文章:

iphone - 启动方向错误

ios - RestKit核心数据“managedObjectStore为零”

ios - UIWebView 获取SPA(单页应用)网站的当前URL

iphone - 是否可以在 iOS 上使用 Quartz 从 PDF 数字中获取 double 值?

iOS 更改方向时更改 UI 的最佳方式

iphone - 确定 iPad 上的 UIInterfaceOrientation

ios - Flurry AppSpot 测试广告未出现在设备上

javascript - HTML 中的 UINavigationController 类型菜单

android - 通过加速度计算方向

ios - 如何在 Swift 的横向模式下更改图标的旋转?