开发者

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");
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜