Reputation: 1634
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)
}
Upvotes: 9
Views: 12945
Reputation: 1634
I found the solution:
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)
}
Upvotes: 15