不管IOS 13中的视图层次如何,都将ViewController放在一切之上 [英] Present ViewController on top of everything regardless of the view hierarchy in IOS 13
本文介绍了不管IOS 13中的视图层次如何,都将ViewController放在一切之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在iOS 13中,出现模态视图控制器时有一个新行为.现在默认情况下它不是全屏的,当我尝试将modalPresentationStyle更改为.fullScreen时,我的视图出现并立即关闭.我正在用代码呈现视图控制器:
In iOS 13,there is a new behaviour for modal view controller when being presented. Now it's not fullscreen by default, and when i try to change modalPresentationStyle to .fullScreen my view present and dismiss immediately. I'm presenting view controller with code :
if #available(iOS 13.0, *) {
var popupWindow: UIWindow?
let windowScene = UIApplication.shared
.connectedScenes
.filter { $0.activationState == .foregroundActive }
.first
if let windowScene = windowScene as? UIWindowScene {
popupWindow = UIWindow(windowScene: windowScene)
}
let vc = UIViewController()
vc.view.frame = UIScreen.main.bounds
popupWindow?.frame = UIScreen.main.bounds
popupWindow?.backgroundColor = .clear
popupWindow?.windowLevel = UIWindow.Level.statusBar + 1
popupWindow?.rootViewController = vc
popupWindow?.makeKeyAndVisible()
popupWindow?.rootViewController?.present(self, animated: true, completion: nil)
}
推荐答案
我找到了解决方法:
if #available(iOS 13.0, *) {
if var topController = UIApplication.shared.keyWindow?.rootViewController {
while let presentedViewController = topController.presentedViewController {
topController = presentedViewController
}
self.modalPresentationStyle = .fullScreen
topController.present(self, animated: true, completion: nil)
}
这篇关于不管IOS 13中的视图层次如何,都将ViewController放在一切之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文