我遇到了一个问题,当我创建一个明确的动画从椭圆改变CAShapeLayer的道路的价值一个矩形。CAShapeLayer动画效果路径毛刺/忽明忽暗(从椭圆RECT和背面)
在我的画布控制器我设置基本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
你的答案和一个我从大卫邓肯贴之间,我有一个很好的正在发生的事情的感觉。希望未来版本中的动画路径属性变得更好。 – 2012-03-03 06:58:35
如果您使用弧形矩形方法进行工作,请在此处张贴! – jrturton 2012-03-03 08:32:31
我不知道你是否已经做过这方面的工作,或者自从发布这篇文章后看到任何好的答案。我开始在一个普通的圆上绘制多边形动画,并且目前它正在为一个圆形工作来制作方形动画。我已经张贴该代码作为这个问题的答案,http://stackoverflow.com/questions/28437014/animating-between-two-bezier-path-shapes/28448397#28448397 – rdelmar 2015-02-11 07:09:16