I have many layer-backed views contained in a NSScrollview
and am predominantly concerned with scrolling performance. The documentView
and higher are layer-backed hence their subviews are also layer-backed.
The following are the three natural places that display/rendering code could go:
- override
NSView.wantsUpdateLayer
to return false (or don't do anything because this is the default) & do drawing in NSView'sdrawRect
method - override
NSView.wantsUpdateLayer
to return true & do drawing in NSView'supdateLayer
method - do NO drawing in
NSView
at all & perform all drawing in CALayer'sdrawInContext
method
From the WWDC 2013 Session 215 talk it was stated that (2) is more performant than (1) because the view then doesn't need to create a temporary store for the drawRect output. Firstly, I don't have 100% clarity on when "backing stores" are made and when not and Secondly how do (2) and (3) compare and when might you use one over the other?
In particular, I have to draw text into my view. How would I go about doing that in the updateLayer call? The only examples of drawing text seem to need to get hold of a context - which isn't naturally available in updateLayer
.
来源:https://stackoverflow.com/questions/29109137/layer-backed-nsview-performance-with-rendering-directly-in-calayer-drawincontext