如何将 iPhone SE 的设备方向仅保留为纵向?
How to keep device orientation for iPhone SE exclusively to portrait only?
我正在为我的应用构建横向支持,但我不想支持小 iPhone SE 屏幕,它太难适应横向 UI。
有没有办法让 iPhone SE 只支持纵向,而所有其他 iPhone 机型都支持横向?
我试过这段代码,但对我不起作用。
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if UIDevice.current.modelName == "iPhone 4" ||
UIDevice.current.modelName == "iPhone 5" ||
UIDevice.current.modelName == "iPhone 4s" ||
UIDevice.current.modelName == "iPhone 5s" {
return .portrait
} else {
return .all
}
}
谢谢
切勿根据设备做出布局决定。根据 screen/view 尺码做出决定。
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
let size = UIScreen.main.bounds.size
let len = max(size.height, size.width)
if len <= 480 {
return .portrait
} else {
return .all
}
}
我正在为我的应用构建横向支持,但我不想支持小 iPhone SE 屏幕,它太难适应横向 UI。
有没有办法让 iPhone SE 只支持纵向,而所有其他 iPhone 机型都支持横向?
我试过这段代码,但对我不起作用。
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if UIDevice.current.modelName == "iPhone 4" ||
UIDevice.current.modelName == "iPhone 5" ||
UIDevice.current.modelName == "iPhone 4s" ||
UIDevice.current.modelName == "iPhone 5s" {
return .portrait
} else {
return .all
}
}
谢谢
切勿根据设备做出布局决定。根据 screen/view 尺码做出决定。
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
let size = UIScreen.main.bounds.size
let len = max(size.height, size.width)
if len <= 480 {
return .portrait
} else {
return .all
}
}