支持关闭NSWindow通过转义键显示为表格 [英] Support closing of a NSWindow presented as sheet via escape key

查看:139
本文介绍了支持关闭NSWindow通过转义键显示为表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户按下转义键时,如何设置要关闭的NSWindows(在OS X上)?

How do I setup an NSWindows (on OS X) to be closed when the user presses the escape key?


  • 窗口是通过
    显示为工作表 presentsWindow.beginSheet(mySheetWindow,completionHandler:nil)

  • 它有一个关闭按钮(通过IB)具有设置为'escape'的密钥等价物。此关闭按钮已经正常工作

  • 按下转义会导致系统音频错误输出('Funk' - 声音),但没有记录,也没有关闭窗口。

推荐答案

您必须添加常规按钮并将其放置在窗口的左上角。将按钮宽度和alpha设置为0.

You have to add a regular button and position it at the top left corner of your window. Set your button width and alpha to 0.

请点击在关键等效字段并按ESC键。它将显示转义键图标

Click at the key equivalent field and press ESC. It will show the escape key icon

然后为隐藏按钮创建您的IBAction,如下所示:

Then create your IBAction for the hidden button as follow:

@IBAction func closeWindowAction(sender: AnyObject) {

    window.close()
}

确保您的窗口连接到正确的窗口:

Make sure you have your window outlet connected to the proper window:

@IBOutlet weak var window: NSWindow!

这篇关于支持关闭NSWindow通过转义键显示为表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆