无论 IOS 中的视图层次如何,都在所有内容之上显示 ViewController 13
Present ViewController on top of everything regardless of the view hierarchy in IOS 13
在 iOS 13 中,模态视图控制器在呈现时有一个新行为。现在默认情况下它不是全屏,当我尝试将 modalPresentationStyle 更改为 .fullScreen 我的视图显示并立即关闭。
我正在用代码展示视图控制器:
if #available(iOS 13.0, *) {
var popupWindow: UIWindow?
let windowScene = UIApplication.shared
.connectedScenes
.filter { [=12=].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 中,模态视图控制器在呈现时有一个新行为。现在默认情况下它不是全屏,当我尝试将 modalPresentationStyle 更改为 .fullScreen 我的视图显示并立即关闭。 我正在用代码展示视图控制器:
if #available(iOS 13.0, *) {
var popupWindow: UIWindow?
let windowScene = UIApplication.shared
.connectedScenes
.filter { [=12=].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)
}