NSView Mouse Tracking

I came across strange behavior with Cocoa NSView on Mac OS X.

I have a custom NSView in an NSView container, this custom NSView tracks mouse movements, clicks and has a tooltip. When I add an NSView over the described view, I can still see tooltips, even if the view with the tooltip is below it, but not visible.

I'm sure I misunderstood something in the event processing chain.

Any help really appreciated !;)

Have a nice weekend

Paolo

+6
source share
2 answers

The main problem is that you should not have overlapping views in Cocoa. At least the behavior then becomes undefined. A view may be a subtitle of another view, but not just a sibling within another view.

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

+1
source

If you are no longer using it, you can call the removeFromSuperview method.

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

if you just do not want it to receive events, you can call the resignFirstResponder method

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

Source: https://habr.com/ru/post/908132/


All Articles