带有NSMenu延迟的NSButton-Objective-C /可可 [英] NSButton with delayed NSMenu - Objective-C/Cocoa

查看:94
本文介绍了带有NSMenu延迟的NSButton-Objective-C /可可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 NSButton ,当单击它时会发送一个动作,但是当按下1或2秒钟时会显示一个NSMenu。 此处与该问题完全相同,但由于该答案不存在,为了解决我的问题,我决定再次询问。

I want to create an NSButton that sends an action when it is clicked, but when it is pressed for 1 or two seconds it show a NSMenu. Exactly the same as this question here, but since that answer doesn't solve my problem, I decided to ask again.

例如,转到Finder,打开一个新窗口,浏览某些文件夹,然后单击后退按钮:您转到上一个文件夹。现在单击并按住后退按钮:将显示一个菜单。我不知道如何使用 NSPopUpButton

As an example, go to Finder, open a new window, navigate through some folders and then click the back button: you go to the previous folder. Now click and hold the back button: a menu is displayed. I don't know how to do this with a NSPopUpButton.

推荐答案

使用 NSSegmentedControl

通过发送 setMenu:forSegment:到控件(将任何内容连接到IB中的菜单插座都无法解决问题)。有一个连接到控件的动作(这很重要)。

Add a menu by sending setMenu:forSegment: to the control (connecting anything to the menu outlet in IB won't do the trick). Have an action connected to the control (this is important).

应该完全按照您的描述工作。

Should work exactly as you described.

这篇关于带有NSMenu延迟的NSButton-Objective-C /可可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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