-1
有沒有辦法檢查鼠標是否在視圖中?創建視圖時不調用NSView - mouseEntered
有沒有辦法檢查鼠標是否在視圖中?創建視圖時不調用NSView - mouseEntered
你的問題有點不清楚,但我想你想在你的自定義視圖變得可見時檢測鼠標的位置,如果鼠標位置在視圖的邊界內,則更新它。
如果是這樣,你需要做的是這樣的:
- (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");
}
}