NSEvent - NSLeftMouseDown
我正在尝试使用 NSEvent 和鼠标点击来触发基本功能。例如,按下鼠标左键时关闭窗口。在这个方法中我还需要什么?
谢谢。
- (void)mouseDown:(NSEvent *)theEvent {
if ([theEvent type] == NSLeftMouseDown){
[window orderOut:nil];
}
}
I'm trying to trigger basic functions using NSEvent and mouse clicks. For example close the window when pressing left mouse button. What else do I need in this method?
Thanks.
- (void)mouseDown:(NSEvent *)theEvent {
if ([theEvent type] == NSLeftMouseDown){
[window orderOut:nil];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设这是在自定义视图中,并且
window
出口已连接(或者当视图添加到超级视图时,您使用[self window]
填充该变量),这应该就是你所需要的。不过,我建议处理mouseUp:
而不是mouseDown:
,以便用户有机会通过将鼠标移到视图之外来退出。您还可以考虑使用 NSButton 而不是自定义视图(或在自定义视图内部)。您可以将其直接连接到窗口的
performClose:
或orderOut:
操作。Assuming this is in a custom view and the
window
outlet is connected (or you fill in that variable with[self window]
when the view is added to a superview), that should be all you need. I would suggest handlingmouseUp:
instead ofmouseDown:
, though, to give the user the opportunity to back out by moving the mouse outside of your view.You might also consider using an NSButton instead of (or inside of) a custom view. You could hook it up directly to the window's
performClose:
ororderOut:
action.