Is it possible to observe -visibleRect

I would like to be notified every time a certain NSView - (NSRect)visibleRect , because I want to make some kind of fancy subview layout based on the visible rectangle. Honestly, now I'm at a standstill; -visibleRect does not generate KVO notifications (which makes sense), and there seems to be no way to find out if the visible rectangular has changed or not without explicitly calling -visibleRect .

Is it possible? (or is it a terrible, scary idea?)

+6
source share
3 answers

I think you can either override -[NSView updateTrackingAreas] or listen to NSViewDidUpdateTrackingAreasNotification . This can happen more often than just changing the visible rectangle, but they must happen for any change in the visible rectangle. I think.

However, this can be a terrible idea. Hard to know. :)

+6
source

Another option for post 10.5 is the -viewWillDraw method, which is called just before the view (and its views). You can get the visible view rectangle and execute the layout before calling [super viewWillDraw].

+1
source

Ken, who offers to listen to changes in the tracking area, feels hacked, but seems to work, although they only start after resizing is complete. If you need updates while resizing as it was done, this override -[NSView resizeWithOldSuperviewSize:] will do this

0
source

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


All Articles