【发布时间】:2018-03-03 03:19:06
【问题描述】:
我想为我的应用程序添加一个新的方向设置,让用户选择纵向、横向或操作系统设置。 我找到了一些需要覆盖 UIViewController 的解决方案。 有什么简单的方法吗?
我想拦截和模拟系统的方向变化事件?有可能吗?
【问题讨论】:
标签: ios user-interface settings orientation
我想为我的应用程序添加一个新的方向设置,让用户选择纵向、横向或操作系统设置。 我找到了一些需要覆盖 UIViewController 的解决方案。 有什么简单的方法吗?
我想拦截和模拟系统的方向变化事件?有可能吗?
【问题讨论】:
标签: ios user-interface settings orientation
实现下面的UIApplicationDelegate 方法并根据用户选择的设置返回适当的掩码:
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
// The following conditions are pseudo code to give you an idea
if "userSetting == portrait" {
return .portrait
} else if "userSetting == landscape" {
return .landscape
} else {
return .all
}
}
还要确保您的 Info.plist 指定所有方向。
【讨论】: