2011-07-07 102 views

回答

0

你的问题有点不清楚,但我想你想在你的自定义视图变得可见时检测鼠标的位置,如果鼠标位置在视图的边界内,则更新它。

如果是这样,你需要做的是这样的:

- (void)viewDidMoveToWindow 
{ 
    if(![self window]) 
     return; 

    NSPoint mouseLocation = [[self window] mouseLocationOutsideOfEventStream]; 

    if(NSPointInRect(mouseLocation, [self frame])) 
    { 
     NSLog(@"mouse is over the view"); 
    } 
    else 
    { 
     NSLog(@"mouse is not over the view"); 
    } 

}