我有一个iOS应用程序,我在其中提供了一个视图控制器,以便显示全屏广告。这是我的GameViewController
。
当我呈现GameViewController
时,现有内容会自动向后推一点,远离用户(我想是按比例缩小(我希望现有内容保持不变,而不缩减
为了呈现GameViewController
,我首先获取根视图控制器,如下所示:
let rootViewController = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
然后,我在根视图控制器上调用present
,传入GameViewController
作为第一个参数,如下所示:
rootViewController?.present(self, animated: false) {
//Load the advertisement.
}
我尝试了modalPresentationStyle
属性的实验,如下所示:
rootViewController?.modalPresentationStyle = .overFullScreen
问题:在演示视图控制器时,如何阻止现有内容被缩小/推离用户?
谢谢!
尝试tis:
let controller = GameViewController()
controller.modalPresentationStyle = .fullScreen
present(controller, animated: true, completion: nil)
评论后编辑
试试看:
let controller = GameViewController()
controller.modalPresentationStyle = .overCurrentContext
controller.view.backgroundColor = UIColor(white: 0, alpha: 0.5) // or you can set it in your destination controller
present(controller, animated: true, completion: nil)