Для обработки событий вы должны реализовать соответствующие методы NSResponder в своем подклассе NSView или NSViewController. Например, вы можете реализовать mouseDown:
и -mouseUp:
для обработки щелчков мыши (довольно упрощенно), например:
- (void) mouseDown: (NSEvent *) event
{
if ( [event type] != NSLeftMouseDown )
{
// not the left button, let other things handle it
[super mouseDown: event];
return;
}
NSPoint location = [self convertPoint: [event locationInWindow] fromView: nil];
if ( !NSPointInRect(location, self.theRect) )
{
[super mouseDown: event];
return;
}
self.hasMouseDown = YES;
}
- (void) mouseUp: (NSEvent *) event
{
if ( (!self.hasMouseDown) || ([event type] != NSLeftMouseUp) )
{
[super mouseUp: event];
return;
}
NSPoint location = [self convertPoint: [event locationInWindow] fromView: nil];
if ( !NSPointInRect(location, self.theRect) )
{
[super mouseDown: event];
return;
}
self.hasMouseDown = NO;
// mouse went down and up within the target rect, so you can do stuff now
}