我在当前的UIViewController
(我们称之为 Controller B)上展示了一个UIViewController
(我们称之为 Controller A)。我希望 Controller A 处于横向状态。当我设置 overCurrentContext
时,默认情况下它不会更改方向(我需要向左/右转设备),但是,如果我注释 overCurrentContext
代码,一切都会工作。
var landscapeOrientation = false
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if landscapeOrientation{
return UIInterfaceOrientationMask.landscapeRight
}else{
return UIInterfaceOrientationMask.portrait
}
}
我如何展示新 Controller 并设置方向。
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:我也在其他一些 Controller 上使用了这个delegate.landspaceOrientation=true
,因为我没有用 overCurrentContext 来呈现它,所以一切都正常,所以没有该代码有问题:)
P.S2:父 Controller 是一个UINavigationController
我认为这个问题对我来说有些问题,但我无法找出所提供的解决方案。 Can a viewcontroller presented modally over current context (UIModalPresentationStyleOverCurrentContext) be rotated with device?
最佳答案
我在一种覆盖 View Controller 中具有相同的效果 - 如果您至少需要背景 View 的全屏“大小”,您可以使用 .overFullScreen 作为 modalPresentationStyle 而不是 .overCurrentContext (它仍然会显示通过某种快照设置背景,但旋转仍然有效)。
关于ios - OverCurrentContext 防止方向改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54359834/