【问题标题】:Correcting UINavigationController orientation更正 UINavigationController 方向
【发布时间】:2016-10-14 13:52:26
【问题描述】:

我有一个 UINavigationControllers 数组,我想从中显示自定义侧菜单控制器。一切正常,但是当我将设备方向更改为横向,然后从先前呈现为纵向的数组中呈现 UINavigationController 时,它不会旋转它只会显示在屏幕外......有没有办法在显示之前纠正 UINavigationControllers 方向?

我是这样介绍它们的:

func presentNavigationViewController(_ navigationViewController: UINavigationController) {

    //// removing old centerNavigationController
    self.centerNavigationController?.view.removeFromSuperview()
    self.centerNavigationController?.view.removeGestureRecognizer(panGestureRecognizer)
    self.centerNavigationController?.removeFromParentViewController()

    self.centerNavigationController = navigationViewController

    //// corecting view position based on status of side menu
    switch self.currentState {
    case .Expanded:
        self.centerNavigationController.view.frame.origin.x = centerNavigationController.view.frame.width - ContainerViewController.centerPanelExpandedOffset
    case .Collapsed:
        self.centerNavigationController.view.frame.origin.x = 0
    }

    //// and presenting
    self.view.addSubview(centerNavigationController.view)
    self.addChildViewController(centerNavigationController)        
    self.centerNavigationController.didMove(toParentViewController: self)        
    self.centerNavigationController.view.addGestureRecognizer(panGestureRecognizer)
}

【问题讨论】:

  • 如何展示阵列中的控制器?
  • 我在问题中添加了一些实现细节。

标签: ios swift uinavigationcontroller


【解决方案1】:

我暂时解决了设置后立即纠正框架的问题

self.centerNavigationController = navigationViewController

像这样

self.centerNavigationController.view.frame = self.view.frame

但我认为它不是理想的解决方案...

【讨论】:

  • 这不是解决方法,而是解决方案。但是,不要使用self.view.frame。相反,请使用self.view.bounds
猜你喜欢
  • 1970-01-01
  • 2013-01-02
  • 2018-10-07
  • 2015-06-01
  • 2012-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-22
相关资源
最近更新 更多