【问题标题】:OverCurrentContext prevents orientation changeOverCurrentContext 防止方向改变
【发布时间】:2019-01-25 06:12:23
【问题描述】:

我在电流UIViewController(我们称之为控制器B)上呈现一个UIViewController(我们称之为控制器A)。我希望控制器 A 以横向显示。当我设置overCurrentContext 时,默认情况下它不会改变方向(我需要向左/向右转动设备),但是,如果我注释overCurrentContext 代码,一切正常。

var landscapeOrientation = false
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    if landscapeOrientation{
        return UIInterfaceOrientationMask.landscapeRight
    }else{
        return UIInterfaceOrientationMask.portrait
    }
}

我如何展示新控制器并设置方向。

let delegate = UIApplication.shared.delegate as! AppDelegate
delegate.landscapeOrientation = true

let controller = ToolTipWithCheckImageViewController()
controller.view.backgroundColor = .clear
controller.modalPresentationStyle = .overCurrentContext //Which causes the bug
controller.modalTransitionStyle = .crossDissolve
topController.present(controller, animated:true)

P.S:我也在其他一些控制器上使用了这个delegate.landspaceOrientation=true,因为我没有使用overCurrentContext 来呈现它,所以一切正常,所以该代码没有问题:)

P.S2:父控制器是UINavigationController

我认为这个问题对我有一些问题,但我无法弄清楚所提供的解决方案。 Can a viewcontroller presented modally over current context (UIModalPresentationStyleOverCurrentContext) be rotated with device?

【问题讨论】:

    标签: ios swift orientation


    【解决方案1】:

    我在一种覆盖视图控制器中也有同样的效果——如果你至少需要一个全屏“大小”作为背景视图,你可以使用 .overFullScreen 作为 modalPresentationStyle 而不是 .overCurrentContext(它仍然会显示背景通过一种快照,但旋转仍然有效)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      相关资源
      最近更新 更多