简体   繁体   中英

NSView mouse tracking

I'm facing a strange behavior with Cocoa NSView on Mac OS X.

I've a custom NSView in a NSView container, this custom NSView tracks mouse movements, clicks, and has a tooltip. When I add a NSView above the described view, I can still see the tooltips even if the view with the tooltip is under, behind and not visible.

I'm pretty sure that I misunderstood something in the event handling chain. Any help is really appreciated!

The core issue is that you are not supposed to have overlapping views in Cocoa. Or at least, the behavior then becomes undefined. A view can be a subview of another view, but not simply a sibling within the bounds of the other view.

However, one way to solve your particular problem is to make the view underneath hidden, using the setHidden: method.

If you're not using it anymore you can call the removeFromSuperview method.

NSView *myView
[myView alloc] init]
// do stuff
[myView removeFromSuperview]

if you just don't want it to receive events you can call the resignFirstResponder method

NSView *myView
[[myView alloc] init] 
// do stuff
[myView resignFirstResponder]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM