ios - 屏幕方向?

标签 ios iphone swift sprite-kit

如何确保唯一允许的方向是纵向或倒置纵向?

我在项目设置中进行了更改,但在我的 GameViewController 中进行更改时遇到了问题。

我需要修改这个函数:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .AllButUpsideDown
    } else {
        return .All
    }
}

但是,“UIInterfaceOrientationMask”结构没有只允许纵向和倒置纵向的选项。

最佳答案

您必须在项目设置中允许所有方向,然后除了 GameViewController 之外,您的 viewController 中唯一允许的方向是纵向或颠倒纵向:

// BaseViewController
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return UIInterfaceOrientationMask.Portrait.rawValue | UIInterfaceOrientationMask.PortraitUpsideDown.rawValue
    } else {
        return .All
    }
}

最后在 GameViewController 中:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .AllButUpsideDown
    } else {
        return .All
    }
}

关于ios - 屏幕方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30836724/

相关文章:

php - 在 iPhone 上获取数据

ios - 如何让 UITableView 忽略 UINavigationController

ios - Swift UIWebView Pdf 查看 UIActivityViewController 错误

ios - 如何使用 AirDrop 同时发送文本(或 URL)和图像

ios - 由于未捕获的异常而终止应用程序,原因 : 'attempt to delete row 3 from section 1 which only contains 0 rows before the update'

iphone - Xcode ProcessPCH iPhone模拟器编译报错

iphone - 在 iPhone 中显示格式化字符串中小数点后两位数的浮点值

ios - 使用 swift 显示从 url 下载的图像的加载百分比

ios - 无法将类型 'NSURL' 的值转换为 'SocketIO.SocketManagerSpec

ios - SwiftUI 无法点击 HStack 的 Spacer