【问题标题】:Disable Landscape for Split View Controller for iPhone in Universal App在通用应用程序中为 iPhone 的拆分视图控制器禁用横向
【发布时间】:2016-06-29 07:23:57
【问题描述】:

我有一个带有UISplitViewController 的通用应用程序。我希望 iPad 版本可以纵向和横向工作,但我只希望应用程序在 iPhone 上纵向工作。我尝试在我的主视图控制器上使用以下内容,但它不起作用:

override func shouldAutorotate() -> Bool {
    return false
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.Portrait
}

我认为问题在于拆分视图控制器覆盖了这两种方法。有什么想法吗?

【问题讨论】:

    标签: ios objective-c iphone swift ipad


    【解决方案1】:

    我想这就是你要找的东西

      [splitViewController setHidesMasterViewInPortrait:NO];
    

    【讨论】:

    • 我想同时禁用横向
    • 我在 UISplitViewController 上看不到这个属性了。
    【解决方案2】:

    我设法通过在AppDelegate 中设置支持的应用界面方向来解决这个问题:

    let deviceIdiom = UIScreen.mainScreen().traitCollection.userInterfaceIdiom
    
    func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
        if deviceIdiom == .Pad {
            return UIInterfaceOrientationMask.All
        }
        return UIInterfaceOrientationMask.Portrait
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-13
      相关资源
      最近更新 更多