在Cocoa中,当鼠标被按住(但不移动)时,我的NSView如何接收事件?

发布于 2024-09-14 03:05:18 字数 228 浏览 0 评论 0原文

我正在寻找正确的方法来处理 NSView 子类中的“鼠标按住一处”事件。

我很熟悉Cocoa的mouseDragged:事件,但它只有在鼠标移动时才会触发。如果鼠标停留在同一位置,则不会触发拖动事件。同样,mouseDown: 仅在第一次按下按钮时触发。只要鼠标在特定区域按住,我的视图就需要执行操作。

做这种事情的正确方法是什么?

I'm looking for the right way to handle "mouse held down in one spot" events in my NSView subclass.

I am familiar with Cocoa's mouseDragged: event, but it is only triggered when the mouse moves. If the mouse stays in the same position, no drag event is triggered. Similarly, mouseDown: is only fired when the button is first pressed. My view needs to perform an action as long as the mouse is held down in a particular region.

What is the proper way to do this kind of thing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一向肩并 2024-09-21 03:05:18

您是否可以在收到 mouseDown: 事件时开始执行操作,并在收到 mouseUp:(或 mouseDragged:)时停止,如果您愿意的话那么也停止)?

Can you start performing the action when you receive a mouseDown: event, and stop when you receive mouseUp: (or mouseDragged:, if you want to stop then, too)?

从来不烧饼 2024-09-21 03:05:18

我不确定您到底想要完成什么,但如果您希望在 mouseDown: 之后以设定的时间间隔重复某个操作,您可以在 中设置一个重复的 NSTimer一旦发生 mouseDragged:mouseUp: 事件,mouseDown: 方法就会被取消。

I'm not sure exactly what you're trying to accomplish, but if you want an action to be repeated at set time intervals after the mouseDown:, you could set a recurring NSTimer in the mouseDown: method that gets cancelled as soon as there is a mouseDragged: or mouseUp: event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文