开发者

Event for Red Close button of NSWindowController

开发者 https://www.devze.com 2023-03-02 01:13 出处:网络
Ho开发者_运维百科w can I handle an event where I click on the red close button of a NSWindowController?

Ho开发者_运维百科w can I handle an event where I click on the red close button of a NSWindowController?

Reason for asking is that I have a video playing in a new NSWindowController window and when user clicks on the red close button, the audio continues playing, so I want to use the event to close the video.


Make your NSWindowController subclass conform to the NSWindowDelegate protocol and be the delegate of the corresponding window. Having done that, implement:

- (void)windowWillClose:(NSNotification *)notification {
    // whichever operations are needed when the
    // window is about to be closed
}

in your NSWindowController subclass.


In my case, I need to observe the event, see https://stackoverflow.com/a/44721893/1418457

NotificationCenter.default.addObserver(self, selector: #selector(windowWillClose(_:)), name: Notification.Name.NSWindowWillClose, object: nil)
0

精彩评论

暂无评论...
验证码 换一张
取 消