From the docs:
"The order that setsWantsLayer: and setLayer: is called is it makes a distinction between a level-supported view and a layer-level view."
"A layer-supported view is a view that is supported by a basic animation layer. Any drawing made with a view is cached at the background level. You set up a layer-supported view by calling setWantsLayer: with a value of YES The view class automatically creates a backup layer for you ( using makeBackingLayer, if overridden), and you should use the drawing classes of the view classes. When using layer-based views, you should never interact directly about with a layer. Instead, you should use the standard kind of programming. "
“A hosting layer is a view that contains a Core Animation layer that you intend to manipulate directly. You create a host-level view by instantiating a class of the Core Animation class and exposing this layer to the setLayer method: After that, you call setWantsLayer: with a value of YES. This the order of the methods is critical.When using a layer-level view, you should not rely on the view to draw, nor should you add a subview to the layout-level view. The one set by setLayer :) should be considered the root layer of the layer tree and you should use only Core Animation drawings and animations. You are still using the view to handle mouse and keyboard events, but any resulting artwork should be handled by Core Animation. "
Since you are supplying your own layer, instead of wanting Cocoa to create it for you, try it this way.
// Create a root layer CALayer *_rootLayer = [CALayer layer]; _rootLayer.shouldRasterize = YES; _rootLayer.name = DAViewRootLayerDefaultName; self.layer = _rootLayer; // Make layer-backed by default self.wantsLayer = YES;
Or, alternatively, take the one that Cocoa gives you and not create your own.
source share