I have a problem when I create an explicit animation to change the value of the CAShapeLayer path from ellipse to rectangle.
In my canvas controller, I set the base CAShapeLayer and add it to the root view layer:
CAShapeLayer *aLayer; aLayer = [CAShapeLayer layer]; aLayer.frame = CGRectMake(100, 100, 100, 100); aLayer.path = CGPathCreateWithEllipseInRect(aLayer.frame, nil); aLayer.lineWidth = 10.0f; aLayer.strokeColor = [UIColor blackColor].CGColor; aLayer.fillColor = [UIColor clearColor].CGColor; [self.view.layer addSublayer:aLayer];
Then, when I animate the path, I get a strange glitch / flicker in the last few frames of the animation when the figure becomes straight, and in the first few frames when it animates away from the straight. The animation is configured as follows:
CGPathRef newPath = CGPathCreateWithRect(aLayer.frame, nil); [CATransaction lock]; [CATransaction begin]; [CATransaction setAnimationDuration:5.0f]; CABasicAnimation *ba = [CABasicAnimation animationWithKeyPath:@"path"]; ba.autoreverses = YES; ba.fillMode = kCAFillModeForwards; ba.repeatCount = HUGE_VALF; ba.fromValue = (id)aLayer.path; ba.toValue = (__bridge id)newPath; [aLayer addAnimation:ba forKey:@"animatePath"]; [CATransaction commit]; [CATransaction unlock];
I tried a lot of different things, such as locking / unlocking CATransaction, playing with different fill modes, etc.
Here's a breakdown image: http://www.postfl.com/outgoing/renderingglitch.png
A video of what I'm experiencing can be found here: http://vimeo.com/37720876
C4 - Travis
source share