To create a new UIWindow over the main window

后端 未结 8 2419

In my app I want to create a new UIWindow over the main UIWindow, And I wrote as following, but it don\'t works. first, i create a UIWindow as the

8条回答
  •  没有蜡笔的小新
    2020-12-07 23:11

    Xcode 8 + Swift

    class ViewController: UIViewController {
        var coveringWindow: UIWindow?
        
        func coverEverything() {
            coveringWindow = UIWindow(frame: (view.window?.frame)!)
            
            if let coveringWindow = coveringWindow {
                coveringWindow.windowLevel = UIWindowLevelAlert + 1
                coveringWindow.isHidden = false
            }
        }
    }
    

    According to the documentation, to receive events that do not have a relevant coordinate value, such as keyboard entry, make it key instead of merely ! isHidden:

    coveringWindow.makeKeyAndVisible()
    

    You can even control the transparency of its background, for a smoke effect:

    coveringWindow.backgroundColor = UIColor(white: 0, alpha: 0.5)
    

    Note that such window needs to handle orientation changes.

提交回复
热议问题