仅在iPhone上锁定方向

时间:2017-10-28 11:47:03

标签: ios swift xcode

如何仅在iPhone上锁定方向

检测设备是iPhone

if UIDevice().userInterfaceIdiom == .phone {
    switch UIScreen.main.nativeBounds.height {
    case 1136:
        print("iPhone 5,5S,5C")
    case 1334:
        print("iPhone 6,6S,7,8")
    case 2208:
        print("iPhone 6+,6S+,7+,8+")
    case 2436:
        print("iPhone X")
    default:
        print("unknown")
    }
}

我使用此代码,但他在iPhone和iPad上是锁定方向

在ViewDidLoad中:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
                return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
}

1 个答案:

答案 0 :(得分:1)

您只需在info.plist

中进行设置即可

也许这回答了你的问题? https://stackoverflow.com/a/30537068/8364981