当我创建一个显式动画来将CAShapeLayer的路径值从椭圆更改为矩形时,我遇到了一个问题.
在我的画布控制器中,我设置了一个基本的CAShapeLayer并将其添加到根视图的图层:
CAShapeLayer *aLayer; aLayer = [CAShapeLayer layer]; aLayer.frame = CGRectMake(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