Listen for window resize event in Swift / Objective-C

前端 未结 4 1398
忘了有多久
忘了有多久 2020-12-30 04:35

Is it possible to iterate over all open windows of any application in OSX and listen to their resize events in Swift? I want to create custom window manager that would move

4条回答
  •  庸人自扰
    2020-12-30 05:22

    first step,you should add NSWindowDelegate and function windowWillResize,full code like this:

    class MainWindowController: NSWindowController, NSWindowDelegate {
    
        override var windowNibName: String? {
            return "MainWindowController"
        }
    
        override func windowDidLoad() {
            super.windowDidLoad()
        }
    
        func windowDidResize(notification: NSNotification) {
            //listen the event
        }
    
    }
    

    then you should set the delegate property,set MainWindowController.xib include file window's delegate property to File's Owner.

提交回复
热议问题