OGeek|极客世界-中国程序员成长平台

标题: ios - 锁定方向在 ipad ios 8 swift xcode 6.2 上不起作用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 22:39
标题: ios - 锁定方向在 ipad ios 8 swift xcode 6.2 上不起作用

我像这样将应用程序方向从一般应用程序设置锁定为纵向

portrait

但是当我在 ipad 上运行我的应用程序时,它还是会旋转!?

那么我应该在哪里锁定方向?

为什么苹果在设置中添加了这个功能,而它却不起作用!?

更新:

我也尝试将此 viewController 实现为所有 viewController 的通用。

import Foundation
import UIKit

class GeneralViewController: UIViewController {

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        let value = UIInterfaceOrientation.Portrait.rawValue
        UIDevice.currentDevice().setValue(value, forKey: "orientation")
    }

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


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

    override func shouldAutorotate() -> Bool {
        return false
    }
}

这张图片取 self 应用的主导航 Controller 。

Pic of answer 1

还是不行!

这东西到底是怎么工作的?



Best Answer-推荐答案


您不需要额外的代码,我正在开发 Xcode 7.0.1,我注意到当我将屏幕方向锁定为仅纵向时,它仅锁定在 iPhone 中,也锁定在 iPad 中,您需要选择iPad从设备(而不是通用)并检查纵向并取消选中其他,然后再次将设备返回通用,因为我发现通用仅反射(reflect)在iPhone中,它可能是Xcode中的某种错误。

关于ios - 锁定方向在 ipad ios 8 swift xcode 6.2 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55490424/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4