NSView - mouseEntered not called when view created
Is th开发者_C百科ere a way to check that the mouse is in the view?
Your question is a little unclear but I think you want to detect the position of the mouse when your custom view becomes visible and update it if the mouse position is within the view's bounds.
If so, you need to do something like this:
- (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");
}
}
精彩评论