當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