Touch action not working with top level custom UIWindow for overlay

49 Views Asked by At

I made custom UIWindow for overlay, and the UserInteractionEnabled is false. It seems working good, touch action in default window's rootViewController. But when I present modal, some official iOS SDK's UI component (ex. CNContactPickerViewController), it does not working for touch action.

  1. There is default window and default rootViewController.
  2. I made new UIWindow for overlay.
  3. The Overlay window's "userInteractionEnabled" is false, and their subviews's "userInteractionEnabled" is false as well.
  4. makeKeyAndVisible for default window and overlayWindow
  5. The default viewController is working good touch action.
  6. I presented CNContactPickerViewController as modal, but the picker view controller is not working for touch action.
  7. I tested another official UI components as well, but action is not working. ex) PHPhotoPickerViewController, UIActivityViewController, UIDocumentPickerViewController, and so on...
    var window: UIWindow?
    var overlayWindow: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        guard let windowScene = (scene as? UIWindowScene) else { return }
        
        overlayWindow = UIWindow(windowScene: windowScene)
        overlayWindow?.clipsToBounds = true
        overlayWindow?.backgroundColor = UIColor.clear
        overlayWindow?.isUserInteractionEnabled = false

        let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let overlayViewController = mainStoryboard.instantiateViewController(withIdentifier: "OverlayViewController") as! OverlayViewController
        overlayWindow?.rootViewController = overlayViewController

        overlayWindow?.windowLevel = UIWindow.Level(UIWindow.Level.statusBar.rawValue + 10)
        let screenSize = UIScreen.main.bounds.size
        overlayWindow?.frame = CGRect(x: 0, y: 0, width: screenSize.width, height: screenSize.height)

        overlayWindow?.makeKeyAndVisible()
        
        self.window?.makeKeyAndVisible()
    }

enter image description here

do you have any good advice?

0

There are 0 best solutions below