如何仅在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)
}