如何避免Xcode在iOS 8中自动旋转?

时间:2014-10-21 12:26:06

标签: xcode ios8 autorotate

我正在使用Xcode,在更新到iOS 8后,shouldAutorotate功能不起作用。 我不希望我的viewcontroller自动旋转。

如何在Xcode中限制iOS 8中的自动旋转?

2 个答案:

答案 0 :(得分:4)

请按照以下步骤操作:

  1. 首先,在info.plist中选择应用程序支持的方向。这意味着如果您的应用程序仅以纵向模式显示,则选择纵向作为您的唯一设置。

    enter image description here

    如果您想从appdelegate限制此方向,可以添加此代码

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
        NSUInteger orientations;
    
        UIViewController* presented = [[[[NavigationManager sharedManager ] navigationController] viewControllers] lastObject];
        orientations = [presented supportedInterfaceOrientations];
    
        return orientations;
    }
    
  2. 为UIViewcontroller创建公共类并添加以下方法:

    BaseViewController.h

    @interface BaseViewController : UIViewController{
    }
    

    BaseViewController.m

    - (BOOL)shouldAutorotate
    {
        return NO;
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    

答案 1 :(得分:0)

在导航控制器类

中添加以下代码
-(BOOL)shouldAutorotate
{

return NO;    
}

-(NSUInteger)supportedInterfaceOrientation

{

    return UIInterfaceOrientationPortrait;

}