如何改变形状(从椭圆形到矩形,反之亦然)动画?
脏代码:
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"];
结果很奇怪:
我希望形状会缩小/扩大,而不是奇怪的重绘。