只允许一个View Controller的所有方向 [英] Allow all orientations for only one view controller

查看:67
本文介绍了只允许一个View Controller的所有方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道此问题已经在此处此处

I know this question was already asked in here, here and here. I tried all possible ways but wasn't successful.

我正在尝试在Swift(iOS 8)中开发一个应用程序,在该应用程序中,只有一个视图控制器可以在所有方向上被查看,而其他视图则只能以纵向显示.

I'm trying to develop an application in Swift (iOS 8), in which only one view controller can be viewed in all orientations others in only portrait.

为此,我仅在目标"->常规"->设备方向"中启用了"Portrait"模式(因为我希望应用程序只能在除一个视图控制器之外的纵向模式下运行).

For this, I have enabled only Portrait mode in Target->General->Device Orientation (because I want the application to operate only in portrait mode except one view controller).

我已将以下代码添加到要在所有方向上操作的视图控制器:

I have added below code to the view controller that I want to operate in all orientations:

override func supportedInterfaceOrientations() -> Int {
    return Int(UIInterfaceOrientationMask.All.rawValue)
}

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
    return UIInterfaceOrientation.LandscapeLeft;
}

override func shouldAutorotate() -> Bool {
    return true;
}

但是无法在横向模式下旋转它.

But couldn't rotate it in landscape mode.

推荐答案

执行以下操作:

  1. 在常规信息"屏幕中启用所需的方向
  2. 在每个ViewController中的
  3. 中,使用true或false覆盖自动旋转功能.
    (true表示应该旋转的一个,false表示其他的旋转):

  1. enable the desired orientations in the General Info Screen
  2. in each ViewController, override the autorotation function with either true or false
    (true for the one that should rotate, false for the others):

override var shouldAutorotate: Bool {
    return true
}

希望有帮助:)

这篇关于只允许一个View Controller的所有方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆