ios - 通用应用程序以纵向模式启动,即使它仅限于横向

标签 ios ipad swift sprite-kit screen-orientation

无论何时在 iPad 上运行模拟,即使在常规设置和代码中它被限制为横向模式,它也会以纵向启动然后切换到横向。问题是当它启动时,所有游戏对象在方向改变之前都被绘制到屏幕上,导致对象被绘制到查看区域下方。用 iPad 横屏模式模拟启动时,一切正常。我怎样才能防止这种情况发生?

我在 GameViewController.swift 中的代码:

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

最佳答案

对于swift3.0

要限制不同 View 的不同方向,您需要执行以下操作:

在应用委托(delegate)文件中:

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

        if self.window?.rootViewController?.presentedViewController is OtherViewController {

            return UIInterfaceOrientationMask.All;

        } else {
            return UIInterfaceOrientationMask.Portrait;
        }

    }

关于ios - 通用应用程序以纵向模式启动,即使它仅限于横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29727387/

相关文章:

iOS 居中对齐引导线,当用户拖动 UILabel 时

ios - 如何从 UIImagePickerController 获取图像的 NSURL?用于上传到 Firebase

ios - 如何在 swift 中设置 webview 窗口的大小?

ios - 如何将渐变添加到 UIView 作为扩展

iphone - UIScrollView 将触摸发送到 subview

ios - 快速确定委托(delegate)属性的类别

ios - 当我在 splitviewcontroller 中更改方向时,rightbarbuttomitem 超出范围

android - 移动设备和 HTML5 应用程序的合理缩略图大小是多少?

ios - 在 Xamarin.Forms 中检查用户使用的是 iPhone 还是 iPad

ios - 在列表和详细信息 ViewController 中重用相同的 View