I am following this answer to create a gradient using a CALayer
. The
key command is
[view.layer insertSublayer:gradient atIndex:0];
My problem is that I would like to update the gradient regularly. If I call the above code repeatedly, then nothing happens as new gradients are placed under the old ones. See this answer.
My question is: how does one replace a sublayer with another one. I should probably call
replaceSublayer:with:
. But to do this, I need a reference to the old gradient. Is there a dynamic way of obtaining this. Something like [view.layer getSublayerAtIndex: 0]
? Is the easiest way to just store a reference to the current gradient in the viewcontroller?
Ideas?