问题
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.wantsUpdateLayerto return false (or don't do anything because this is the default) & do drawing in NSView'sdrawRectmethod - override
NSView.wantsUpdateLayerto return true & do drawing in NSView'supdateLayermethod - do NO drawing in
NSViewat all & perform all drawing in CALayer'sdrawInContextmethod
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