Keep window always on top?

后端 未结 3 1103
眼角桃花
眼角桃花 2020-11-29 01:45

In Objective-C for Cocoa Apps it\'s possible to use such way to keep window always on top?

How to achieve the same with Swift?

self.view.window?.leve         


        
3条回答
  •  北海茫月
    2020-11-29 02:32

    To change the window level you can't do it inside viewDidload because view's window property will always be nil there but it can be done overriding viewDidAppear method or any other method that runs after view is installed in a window (do not use it inside viewDidLoad):

    Swift 4 or later

    override func viewDidAppear() {
        super.viewDidAppear()
        view.window?.level = .floating
    }
    

    For older Swift syntax check the edit history

提交回复
热议问题