How to redraw UIView sublayers when I am animating UIView borders?

I have a UIView with several subscript subsets (several CAGradientLayers with CAShapeLayer masks, etc.). I use the UIView animation method to animate its borders (increasing both its width and height).

[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseOut|UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{ CGRect bounds = myView.bounds; bounds.size.width += 20; bounds.size.height += 20; myView.bounds = bounds; } completion:nil]; 

This works great, except for the fact that subwords are not redrawn as animations. What is the best way to do this? Do I need to set some detection limits for detecting a key value and call setNeedsDisplay on all sublayers?

+4
source share
2 answers

Layers do not work as representations. If you call setNeedsDisplay (which happens if you set requireDisplayOnBoundsChange to YES) on the parent layer, this will not affect the child layers. You also need to call setNeedsDisplay.

If your sublayers need to be changed also when the size of the parent layer is changed, then implement layoutSublayers in the parent (or layoutSublayersOfLayer: in your deletion).

+3
source

Set contentMode to UIViewContentModeRedraw to the animation you are animating.

+6
source

All Articles