【问题标题】:How to allow iOS users to set the application's orientation如何允许 iOS 用户设置应用程序的方向
【发布时间】:2018-03-03 03:19:06
【问题描述】:

我想为我的应用程序添加一个新的方向设置,让用户选择纵向、横向或操作系统设置。 我找到了一些需要覆盖 UIViewController 的解决方案。 有什么简单的方法吗?

我想拦截和模拟系统的方向变化事件?有可能吗?

【问题讨论】:

    标签: ios user-interface settings orientation


    【解决方案1】:

    实现下面的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 指定所有方向。

    【讨论】:

    • 应用启动时工作。但是在用户更改设置后它不起作用。有没有办法通知设置更改?
    • 此方法从不在 iPad 模拟器中调用。但它可以在真正的 iPad 上运行。我很困惑
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 2021-05-17
    • 2014-08-22
    相关资源
    最近更新 更多