【问题标题】:Using General tab, unable to lock device orientation of the app for iPad使用常规选项卡,无法锁定 iPad 应用程序的设备方向
【发布时间】:2019-02-20 09:04:58
【问题描述】:

我正在使用 Xcode 9.4。在 .xcodeproj 文件中,在 General 选项卡下,我未选中 Portrait 和 Upside Down 选项。应用程序仍会旋转到这两种模式。请帮我做同样的事情

提前谢谢你。

【问题讨论】:

    标签: ios swift ipad device-orientation


    【解决方案1】:

    AppDelegate,如果你旋转设备,推送viewController等,这个函数总是调用

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

    使用:

    在 AppDelegate 中:

    var restrictRotation:UIInterfaceOrientationMask = .portrait
    

    & 在 vi​​ewController 中调用 ViewDidLoad 或 viewWillAppear 方法时。我们会这样改变:

    (UIApplication.shared.delegate as! AppDelegate).restrictRotation = .all 
    

    然后会调用 AppDelegate 上的这个方法。

    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-27
      • 2014-08-10
      • 1970-01-01
      相关资源
      最近更新 更多