UIWindow not showing over content in iOS 13

后端 未结 12 1682
野的像风
野的像风 2020-12-07 17:41

I am upgrading my app to use the new UIScene patterns as defined in iOS 13, however a critical part of the app has stopped working. I have been using a UI

12条回答
  •  天涯浪人
    2020-12-07 18:25

    In addition to the answers about creating a reference to UIWindow and then presenting modally, I've included a section of my code on how I'm dismissing it.

    class PresentingViewController: UIViewController {
        private var coveringWindow: UIWindow?
    
      func presentMovie() {
        let playerVC = MoviePlayerViewController()
        playerVC.delegate = self
        playerVC.modalPresentationStyle = .overFullScreen
        playerVC.modalTransitionStyle = .coverVertical
    
        self.coverPortraitWindow(playerVC)
      }
    
      func coverPortraitWindow(_ movieController: MoviePlayerViewController) {
    
        let windowScene = UIApplication.shared
            .connectedScenes
            .filter { $0.activationState == .foregroundActive }
            .first
        if let windowScene = windowScene as? UIWindowScene {
            self.coveringWindow = UIWindow(windowScene: windowScene)
    
            let rootController = UIViewController()
            rootController.view.backgroundColor = .clear
    
            self.coveringWindow!.windowLevel = .alert + 1
            self.coveringWindow!.isHidden = false
            self.coveringWindow!.rootViewController = rootController
            self.coveringWindow!.makeKeyAndVisible()
    
            rootController.present(movieController, animated: true)
        }
      }
    
      func uncoverPortraitWindow() {
        guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
            let sceneDelegate = windowScene.delegate as? SceneDelegate
            else {
                return
        }
        sceneDelegate.window?.makeKeyAndVisible()
        self.coveringWindow = nil
      }
    
    }
    

提交回复
热议问题