在你的NSView子類可以覆蓋各種鼠標事件處理程序做任何你想要的:
- (void)mouseDown:(NSEvent *)event;
- (void)mouseDragged:(NSEvent *)event;
- (void)mouseUp:(NSEvent *)event;
然後,你需要一種方法來知道在哪裏圈是這樣,你就會知道,當他們」已經被點擊了。如果你有一個圓作爲NSPoint和半徑,那麼類似這樣的事情會起作用
- (BOOL)isPoint:(NSPoint)click inCircleAtPoint:(NSPoint)centre withRadius:(float)r
{
float dx = click.x - centre.x;
float dy = click.y - centre.y;
// Get the distance from the click to the centre of the circle
float h = hypot (dx, dy);
// is the distance less than the radius?
return (h < r);
}
- (void)mouseDown:(NSEvent *)event
{
NSPoint clickPoint = [event locationInWindow];
if ([self isPoint:clickPoint inCircleAtPoint:mapPoint withRadius:5.0]) {
// Click was in point
}
}