【问题标题】:One controller in landscape orientation一个横向控制器
【发布时间】:2015-10-27 16:58:32
【问题描述】:

我有一个应用程序,它由一个包含 4 个导航控制器的标签栏控制器组成。我找不到任何解决方案让导航控制器层次结构中的一个控制器仅处于横向模式。所有其他控制器都应该是纵向的。感谢您对此问题的任何帮助。

【问题讨论】:

    标签: ios uinavigationcontroller orientation landscape


    【解决方案1】:

    在你想成为横向的导航控制器的viewDidLoad():中,包括:

    let value = UIInterfaceOrientation.LandscapeLeft.rawValue
    UIDevice.currentDevice().setValue(value, forKey: "orientation")
    

    请务必添加以下覆盖

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

    【讨论】:

    • 我将此代码添加到导航控制器,它在 iOS 8 上不起作用,应该自动旋转从未调用过。看来这在最新的iOS中是个大问题。
    【解决方案2】:

    所以我尝试了以下解决方案,它对我有用:

    在 AppDelegate.swift 中:

    var currViewController: UIViewController?
    
    func application(application: UIApplication, supportedInterfaceOrientationForWindows window: UIWindow?) -> UIInterfaceOrientationMask {
      if currViewController is MyCustomController {
        return UIInterfaceOrientationMask.LandscapeLeft
      } else {
        return UIInterfaceOrientationMask.Portrait
      }
    }
    

    在 MyCustomController.swift 中:

    let oAppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    
    override func viewDidLoad(){
      super.viewDidLoad()
      oAppDelegate.currViewController = self
    }
    

    【讨论】:

      猜你喜欢
      • 2012-12-09
      • 1970-01-01
      • 2013-08-26
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多