当我创建一个显式动画,将CAShapeLayer的路径从椭圆形更改为矩形时,出现了问题。
在我的画布控制器中,我设置了一个基本的CAShapeLayer并将其添加到根视图的图层中:
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];
然后,当我对路径进行动画处理时,在动画的最后几帧中出现了奇怪的闪烁/闪烁问题,此时形状变为矩形,在从矩形动画消失时的前几帧也有相同的问题。 动画的设置如下:
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];
我尝试了很多不同的方法,比如锁定/解锁CATransaction,调整各种填充模式等...
这里是故障的图像: http://www.postfl.com/outgoing/renderingglitch.png
我遇到的问题视频可以在此找到: http://vimeo.com/37720876