LoginSignup
2
3

More than 5 years have passed since last update.

Borderlessウィンドウで閉じるを有効にする

Posted at

問題

カスタムウィンドウを作る時NSBorderlessWindowMaskを指定すると、デフォルトのウィンドウを閉じる機能が無効化されてしまい、メニューから閉じたり、cmd+wで閉じたりすることができなくなる。

解決法

カスタムウィンドウクラスでvalidateMenuItemをオーバーライドしてperformCloseを有効化させ、performCloseをオーバーライドして閉じる処理を記述する。

class MyWindow: NSWindow {

...

    override func performClose(sender: AnyObject?) {
        // 処理

        ...

        self.close()
    }

    override func validateMenuItem(menuItem: NSMenuItem) -> Bool {
        return menuItem.action == #selector(performClose(_:)) ? true : super.validateMenuItem(menuItem)
    }

...

参考

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3