Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 是否在不缩小现有内容的情况下显示视图控制器?_Ios_Swift - Fatal编程技术网

Ios 是否在不缩小现有内容的情况下显示视图控制器?

Ios 是否在不缩小现有内容的情况下显示视图控制器?,ios,swift,Ios,Swift,我有一个iOS应用程序,其中我提供了一个视图控制器,以便显示全屏广告。这是我的GameViewController 当我呈现GameViewController时,现有内容会自动向后推一点,远离用户(我想是缩小了)我希望现有内容保持不变而不缩减。 为了演示GameViewController,我首先抓取根视图控制器,如下所示: let rootViewController = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.

我有一个iOS应用程序,其中我提供了一个视图控制器,以便显示全屏广告。这是我的
GameViewController

当我呈现
GameViewController
时,现有内容会自动向后推一点,远离用户(我想是缩小了)我希望现有内容保持不变而不缩减。

为了演示
GameViewController
,我首先抓取根视图控制器,如下所示:

let rootViewController = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
rootViewController?.present(self, animated: false) {
   //Load the advertisement.
}
rootViewController?.modalPresentationStyle = .overFullScreen
然后在根视图控制器上调用
present
,传入
GameViewController
作为第一个参数,如下所示:

let rootViewController = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
rootViewController?.present(self, animated: false) {
   //Load the advertisement.
}
rootViewController?.modalPresentationStyle = .overFullScreen
我尝试了
modalPresentationStyle
属性,如下所示:

let rootViewController = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
rootViewController?.present(self, animated: false) {
   //Load the advertisement.
}
rootViewController?.modalPresentationStyle = .overFullScreen
问题:演示视图控制器时,如何阻止现有内容被缩小/推离用户

谢谢大家!

试试看:

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)

与其显示它,不如将其作为子视图控制器加载,并将其视图作为子视图添加到现有视图层次结构中。你可以用任何你想要的方式来制作动画或显示它。这太棒了。关键是在
GameViewController
上设置
modalPresentationStyle
,而不是在根视图控制器上。有一件事:根视图控制器(现有内容)完全变黑了……有没有办法在现有内容上覆盖一个部分透明的覆盖层呢?@West1我会在你的评论后更新我的答案。。。