当我创建显式动画以将 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