如何做转换形状的动画?从椭圆到矩形,从矩形到椭圆。
代码:
UIBezierPath *roundedRectBezierPath = [UIBezierPath bezierPathWithRoundedRect:newRect cornerRadius:10];
UIBezierPath *ovalBezierPath = [UIBezierPath bezierPathWithOvalInRect:newRect];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.duration = 3;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
if (isRect) {
self.shapeLayer.path = roundedRectBezierPath.CGPath;
animation.fromValue = (__bridge id)(ovalBezierPath.CGPath);
animation.toValue = (__bridge id)(roundedRectBezierPath.CGPath);
} else {
self.shapeLayer.path = ovalBezierPath.CGPath;
animation.fromValue = (__bridge id)(roundedRectBezierPath.CGPath);
animation.toValue = (__bridge id)(ovalBezierPath.CGPath);
}
[self.shapeLayer addAnimation:animation forKey:@"animatePath"];
结果如下:
怎么变成这样呢。我希望图片能收缩和膨胀,而不是这样重画。