Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to observe -visibleRect

I would like to be notified whenever a certain NSView's - (NSRect)visibleRect changes because I want to do some fancy subview layout based on the visible rect. Frankly, right now I'm stumped; -visibleRect doesn't emit KVO notifications (which makes sense), and there doesn't seem to be way to find out if the visible rect changed or not without explicitly calling -visibleRect.

Is this at all possible? (or is it a terrible, terrible idea?)

like image 972
Vervious Avatar asked May 26 '12 05:05

Vervious


2 Answers

I think you can either override -[NSView updateTrackingAreas] or listen for NSViewDidUpdateTrackingAreasNotification. Those may happen on more occasions than just a change of the visible rect, but they should happen for any change of the visible rect. I think.

That said, it may be a terrible idea. Hard to know. :)

like image 73
Ken Thomases Avatar answered Oct 21 '22 02:10

Ken Thomases


Another option post 10.5 is the -viewWillDraw method which is called just prior to the view (and its subviews) being drawn. You can fetch the view's visible rectangle and perform layout prior to calling [super viewWillDraw].

like image 26
MrO Avatar answered Oct 21 '22 03:10

MrO