是否有一种方法来检查鼠标是否在视图中?
你的问题有点不清楚,但我认为你想检测鼠标的位置,当你的自定义视图变得可见和更新它,如果鼠标的位置是在视图的边界内。
如果是,你需要做这样的事情:
- (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");
}
}