当NSButton
收到鼠标停止事件时,它将输入一个private tracking loop,处理发布的所有鼠标事件,直到鼠标弹起为止。您可以设置自己的跟踪环路做基于鼠标位置的事情:
- (void) mouseDown:(NSEvent *)event {
BOOL keepTracking = YES;
NSEvent * nextEvent = event;
while(keepTracking){
NSPoint mouseLocation = [self convertPoint:[nextEvent locationInWindow]
fromView:nil];
BOOL mouseInside = [self mouse:mouseLocation inRect:[self bounds]];
// Draw highlight conditional upon mouse being in bounds
[self highlight:mouseInside];
switch([nextEvent type]){
case NSLeftMouseDragged:
/* Do something interesting, testing mouseInside */
break;
case NSLeftMouseUp:
if(mouseInside) [self performClick:nil];
keepTracking = NO;
break;
default:
break;
}
nextEvent = [[self window] nextEventMatchingMask:NSLeftMouseDraggedMask | NSLeftMouseUpMask];
}
}
在你的问题中提到你正在使用'NSTrackingArea'可能是一个好主意。 –
对不起。 –
这仍然帮助我。 – charles