Re: needsDisplay and subviews
Re: needsDisplay and subviews
- Subject: Re: needsDisplay and subviews
- From: Quincey Morris <email@hidden>
- Date: Thu, 09 Mar 2017 09:55:48 -0800
On Mar 9, 2017, at 02:24 , Jeremy Hughes <email@hidden> wrote:
>
> that disagrees with Ben’s conclusion:
>
> "Thus, it seems to follow that so long a custom view's display() calls super, then all of its subviews should also be drawn when its needsDisplay is true.”
I don’t see it as a contradiction. The problem is that “drawing” is ambiguous.
On the one hand, “drawing” means the rendering of model data to image data. This is done via “draw(_:)” for a custom view. Originally this was (I think) the only way to generate view content, but currently there are other ways, such as custom layer-backed views that use the layer-update mechanism, or views with content supplied directly by a CGImage.
On the other hand, “drawing” means transferring content to the display. This involves compositing the backing stores of a view and all of its subviews into a single content “image”, which can then be copied to the display. Note that the actual process might be more complicated, because some views might not have a backing store. That might cause the use of “draw(_:)” for subviews, simply for the purpose of compositing, not because anything has changed in the subview’s view content.
In the case where a view needs to be “redrawn” because (say) it has been revealed by moving something above it, then the only drawing that’s sure to be needed is in the second sense. If all the content is cached in backing stores, no drawing in the first sense is needed. However, uncached content will require drawing in the first sense, too, simply to regenerate the content.
Setting “needsDisplay”, for historical reasons, does not distinguish between the two kinds of drawing. Therefore, it has to be understood in the first sense of drawing — it’s usually used to indicate that the view needs to show different content than it previously did. But it’s also implied that the view will be redrawn in the second sense, too, and *that* sometimes causes subview “draw(_:)” invocations for uncached content, which looks a bit like the recursive application of “needsDisplay”, though it really isn’t.
That’s why I said what I said: Without changes to the model, you only need to set “needsDisplay” at the top level view. With data model changes, you need to set “needsDisplay” on every view whose content is affected by the data change. Beyond those specific views, it’s an implementation detail whether “draw(_:)” is invoked for a subview.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden