On iOS, if a view has several layers, then can the drawRect method just choose any one layer to display, and 1 second later, choose another layer to display, to achieve an animation effect?
Right now, I have several layers, but I don't think they are the view's layers (they are just individual layers which are not sublayers of parent layer), as I just created them using
CGLayerCreateWithContext(context, self.view.bounds.size, NULL);
and in drawRect, I use
CGContextDrawLayerAtPoint(context, self.bounds.origin, layer1);
to draw the layer onto the view... it works, but isn't this like drawing a layer onto a layer (drawing a layer onto the view's layer)? Isn't there a faster way, which is to tell the the view to use layer1 or layer2, kind of like
self.layer = layer1;
but it can't because layer is read only. Can this be achieved?
CGLayers andCALayers. They have similar names but they are entirely different. You cannot mix and match them.CGLayerCreateWithContextmakes aCGLayer, butself.layeris aCALayer. - Kurt RevisCALayerand set itsbackgroundColorproperty. - Kurt Revis