我尝试将圆形更改为正方形,反之亦然,并且我快到了。然而,它并不像预期那样动画。我想一个正方形的各个角落进行动画/在同一时间演变,但我得到的是以下几点:从圆形到方形的iOS动画/变形形状
我以动画形状财产使用CAShapeLayer
和CABasicAnimation
。
这里是我创建的圈子路径:
- (UIBezierPath *)circlePathWithCenter:(CGPoint)center radius:(CGFloat)radius
{
UIBezierPath *circlePath = [UIBezierPath bezierPath];
[circlePath addArcWithCenter:center radius:radius startAngle:0 endAngle:M_PI/2 clockwise:YES];
[circlePath addArcWithCenter:center radius:radius startAngle:M_PI/2 endAngle:M_PI clockwise:YES];
[circlePath addArcWithCenter:center radius:radius startAngle:M_PI endAngle:3*M_PI/2 clockwise:YES];
[circlePath addArcWithCenter:center radius:radius startAngle:3*M_PI/2 endAngle:M_PI clockwise:YES];
[circlePath closePath];
return circlePath;
}
下面是方形路径:
- (UIBezierPath *)squarePathWithCenter:(CGPoint)center size:(CGFloat)size
{
CGFloat startX = center.x-size/2;
CGFloat startY = center.y-size/2;
UIBezierPath *squarePath = [UIBezierPath bezierPath];
[squarePath moveToPoint:CGPointMake(startX, startY)];
[squarePath addLineToPoint:CGPointMake(startX+size, startY)];
[squarePath addLineToPoint:CGPointMake(startX+size, startY+size)];
[squarePath addLineToPoint:CGPointMake(startX, startY+size)];
[squarePath closePath];
return squarePath;
}
我申请的圆圈路径我的看法的一层,设置填充等。它完美地绘制。 然后在我gestureRecognizer选择创建并运行下面的动画:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.duration = 1;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fromValue = (__bridge id)(self.stateLayer.path);
animation.toValue = (__bridge id)(self.stopPath.CGPath);
self.stateLayer.path = self.stopPath.CGPath;
[self.stateLayer addAnimation:animation forKey:@"animatePath"];
正如你可以在circlePathWithCenter:radius:
和squarePathWithCenter:size:
我按照建议从这里看到(有相同数量的段和控制点): Smooth shape shift animation
动画看起来更好,然后从上面的文章,但它仍然不是一个我想要达到:(
我知道,我可以用简单的CALayer
做到这一点,然后设置一个cornerRadius
的适当等级使圆形超出正方形/矩形,之后使用动画cornerRadius
属性将其从圆形更改为方形,但如果甚至可以使用CAShapeLayer
和path
动画完成此操作,我仍然非常好奇。
在此先感谢您的帮助!
它看起来像你有同样的问题,因为这问题[http://stackoverflow.com/questions/17429797/smooth-shape-shift-animation],基于动画 - 可能值得一看 –
嗯..它可能是 - 我知道这个问题,并遵循接受的答案的建议,但我仍然是一个死亡为我结束。我有相同数量的细分/控制点,我认为它们有帮助,因为我的动画形状稍好一些,但是从那里开始的动画却没有线索如何改进。 – fgeorgiew