开发者

NSView - mouseEntered not called when view created

开发者 https://www.devze.com 2023-03-19 00:22 出处:网络
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 u

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

精彩评论

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