在Cocoa中,当鼠标被按住(但不移动)时,我的NSView如何接收事件?
我正在寻找正确的方法来处理 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否可以在收到
mouseDown:
事件时开始执行操作,并在收到mouseUp:
(或mouseDragged:
)时停止,如果您愿意的话那么也停止)?Can you start performing the action when you receive a
mouseDown:
event, and stop when you receivemouseUp:
(ormouseDragged:
, if you want to stop then, too)?我不确定您到底想要完成什么,但如果您希望在
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 themouseDown:
method that gets cancelled as soon as there is amouseDragged:
ormouseUp:
event.