ios - OverCurrentContext 防止方向改变

标签 ios swift orientation

我在当前的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/

相关文章:

ios - Swift 4 可解码,解码错误 : No value associated with key

ios - 如何在 Skype 上共享文本

ios - ios中的联系人选择器以获取电话号码

xcode - FBSDKMessengerSharer 共享音频不起作用

ios - 如何将包 'Storage' 导入到 Swift 项目中?

android - 在 Android PhoneGap 中更改方向时 SplashScreen 未更改

android - 移动景观中的网站,键盘布局问题

ios - 我应该在基于选项卡的应用程序中的哪里实现 facebook 登录?

Android:方向更改会删除对我的 ImageView 所做的修改

ios - Linq 方法 Release模式中的 MonoTouch JIT 错误