【问题标题】:Event for Red Close button of NSWindowControllerNSWindowController 的红色关闭按钮事件
【发布时间】:2011-05-03 05:39:44
【问题描述】:

如何处理单击 NSWindowController 的红色关闭按钮的事件?

询问的原因是我在一个新的 NSWindowController 窗口中播放了一个视频,当用户点击红色关闭按钮时,音频继续播放,所以我想使用该事件来关闭视频。

【问题讨论】:

    标签: cocoa event-handling nswindowcontroller


    【解决方案1】:

    使您的NSWindowController 子类符合NSWindowDelegate 协议并成为相应窗口的委托。完成后,实施:

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

    在您的 NSWindowController 子类中。

    【讨论】:

      【解决方案2】:

      就我而言,我需要观察事件,见https://stackoverflow.com/a/44721893/1418457

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-28
        • 1970-01-01
        相关资源
        最近更新 更多