ios - 在将 View Controller 设置为横向时在 App Delegate 中锁定纵向 View

标签 ios swift landscape

我需要将整个应用程序锁定在 PortraitView 中,一个 View Controller 除外。我需要这些功能的功能,但同时使用这两个功能时出现错误。当我添加 View Controller 功能时,应用程序崩溃。如果我拿走应用程序委托(delegate), View Controller 也会执行我需要的操作。

应用委托(delegate)

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {

        return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
    }

View Controller

 override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .landscapeRight
    }

    override var shouldAutorotate: Bool {
        return true
    }

最佳答案

编辑为使用基本 Controller View :

我记得是否为应用程序启用了方向。需要为每个需要限制它的 Controller 实现方向功能。

或者,创建支持 Portrait 的 Base UIViewController。它应该被所有 Controller 继承,并且只覆盖景观 Controller 中的方向功能。

类似于以下内容:

class BaseViewController : UIViewController {
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .Portrait...
    }
}

class ViewController1: BaseViewController {
    // nothin to override
}

class LandscapeController: BaseViewController {
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .landscapeRight
    }
}

关于ios - 在将 View Controller 设置为横向时在 App Delegate 中锁定纵向 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49242471/

相关文章:

iphone - 如何让我的 iPhone 应用程序以横向模式启动?

ios - iOS 8 中的相机显示黑屏

ios - 如何从其他 Swift 文件调用数据库根目录?

Swift 从 [String :[String:Any]] 的字典中访问内部键和值

macos - Swift - 使用字典 - 添加多个值

swift - NSStatusItem 和 NSMenuItem 检测换档按下

ios - 将相机应用程序旋转复制到风景 IOS 6 iPhone

ios - 我无法将按钮连接到@IBAction

ios - 实现 tableView :heightForFooterInSection: 时,UITableView 的页脚未随表格一起滚动

ios - UIWebview [UIThreadSafeNode _responderForEditing] 崩溃