I'm trying to trigger basic functions using NSEvent and mouse clicks. F开发者_C百科or 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];
}
}
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 handling mouseUp:
instead of mouseDown:
, 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:
or orderOut:
action.
精彩评论