我正在尝试通过使用bezierpath和keyframeanimation来实现动画效果,该效果将模拟波形效果的非常简单的表示。
然而,对于关键帧动画我无法正常获得效果,动画从起点到终点工作,而不是上下波动曲线。
这可以更好地反映正在发生的事情。
这是动画的代码:
CGPoint rightCurve;
rightCurve.x = center.x + radius * cos(startAngle);
rightCurve.y = center.y + radius * sin(startAngle);
CGPoint leftCurve;
leftCurve.x = center.x + radius * cos(endAngle);
leftCurve.y = center.y + radius * sin(endAngle);
CGPoint centerCurve;
centerCurve.x = center.x;
centerCurve.y = leftCurve.y;
CGPoint controlLeftUp = CGPointMake((leftCurve.x + centerCurve.x) /2, ((centerCurve.y + ((centerCurve.x - rightCurve.x)/2)*1.3)));
CGPoint controlLeftDown = CGPointMake((leftCurve.x + centerCurve.x) /2, ((centerCurve.y - ((centerCurve.x - rightCurve.x)/2)*1.3)));
CGPoint controlRightDown = CGPointMake((rightCurve.x + centerCurve.x) /2, ((centerCurve.y - ((centerCurve.x - rightCurve.x)/2)*1.3)));
CGPoint controlRightUp = CGPointMake((rightCurve.x + centerCurve.x) /2, ((centerCurve.y + ((centerCurve.x - rightCurve.x)/2)*1.3)));
UIBezierPath* path0 = [UIBezierPath bezierPath];
[path0 moveToPoint:CGPointMake(leftCurve.x, leftCurve.y)];
[path0 addQuadCurveToPoint:CGPointMake(centerCurve.x, centerCurve.y) controlPoint:controlLeftUp];
[path0 moveToPoint:CGPointMake(centerCurve.x , centerCurve.y)];
[path0 addQuadCurveToPoint:CGPointMake(rightCurve.x, rightCurve.y) controlPoint:controlRightDown];
UIBezierPath* path1 = [UIBezierPath bezierPath];
[path1 moveToPoint:CGPointMake(rightCurve.x,rightCurve.y)];
[path1 addQuadCurveToPoint:CGPointMake(centerCurve.x, centerCurve.y) controlPoint:controlRightUp];
[path1 moveToPoint:CGPointMake(centerCurve.x , centerCurve.y)];
[path1 addQuadCurveToPoint:CGPointMake(leftCurve.x, leftCurve.y) controlPoint:controlLeftDown];
CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"path"];
animation.duration = _animationInterval;
animation.values = [NSArray arrayWithObjects:(id)path0.CGPath, (id)path1.CGPath, nil];
animation.repeatCount = HUGE_VALF;
[shapeLayer addAnimation:animation forKey:nil];
如果有人告诉我如何编辑动画或曲线,那将会很棒。
提前致谢。