你可以在iOS应用程序中全局禁用轮换吗?

say*_*guh 19 xcode ios

我有一个由很多视图控制器组成的应用程序......在项目摘要中,我将纵向方向设置为唯一受支持的设备方向.

但是,当转向侧面时,应用程序仍然会搞砸.

我的问题是,有没有办法通过app委托或其他方式全局禁用自动旋转?

或者我是否必须进入所有视图控制器并添加"shouldAutorotateToInterfaceOrientation"方法?

只是不想错过将它添加到一个或一个......

谢谢!

小智 70

在Info.plist中展开"支持的界面方向"并删除横向项目,使您的应用程序仅以纵向模式运行.


Vai*_*ran 16

现在有三种设备方向键info.plist.

  1. 支持的界面方向(iPad)
  2. 支持的界面方向(iPhone)
  3. 支持的界面方向

第三个是我认为非通用应用程序,其余两个是针对iPad和iPhone.

你应该试一试.

在此输入图像描述


kar*_*rim 11

在努力设置UIViewController shouldAutorotatesupportedInterfaceOrientation方法之后,在iOS6中没有成功,我发现最有效的是在app delegate中设置它.

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)

然而,返回UIInterfaceOrientationMaskPortraitUpsideDown正在崩溃我的应用程序.我不知道我做错了什么!

  • 这适用于iOS 8.结合App的`Info.plist`文件中设置的支持界面方向设置,完美地为我工作 (2认同)

Har*_*ain 5

在根视图控制器的方法中:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
Run Code Online (Sandbox Code Playgroud)

设置'返回NO';

这应该适用于所有视图.