我有一个自定义层支持的NSView,并且已经使用makeBackingLayer方法来返回一个自定义的CALayer子类。我也重写wantUpdateLayer来返回true,从而完全选择层状绘图。图层支持NSView与自定义CALayer不调用updateLayer?
override func makeBackingLayer() -> CALayer {
return Layer() // my custom class with "drawLayer:" implemented
}
override var wantsUpdateLayer:Bool{
return true
}
// never called
override func updateLayer() {
super.updateLayer()
println("updateLayer after")
self.layer?.borderWidth += 1
}
一旦我这样做,我发现,当我设置NSView.needsDisplay = true
其呼叫路由到定制层的drawInContext:方法:为反对updateLayer方法。 它为什么这样做?在我的例子中,我检查了如果我删除了makeBackingLayer
覆盖,我的updateLayer
以预期的方式被调用。
我不能完全明白这一点,但其他实例指出,当您的makeBackingLayer图层为CALayer时,您实际上已将自定义图层托管在父支持图层内。 (对我而言,纯粹的猜测)
此外,考虑到CALayer的drawInContext:更“低级”,两种绘制路线之间会有不同的性能特征吗?看到这个问题的更详细的问题:Layer-backed NSView performance with rendering directly in CALayer.drawInContext:
任何有识之士将不胜感激。
我的财产就像上面那样。不幸的是,这不是答案。 – Sam 2015-03-19 10:57:35