SlowTree
SlowTree

Reputation: 1295

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!

Upvotes: 6

Views: 1016

Answers (2)

charles
charles

Reputation: 11752

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.

Upvotes: 1

moxy
moxy

Reputation: 1624

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]

Upvotes: 0

Related Questions