2 ooomiao oOOMIAO 于 2013.07.05 15:27 提问

iPhone-转换形状的动画

如何做转换形状的动画?从椭圆到矩形,从矩形到椭圆。

代码:

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"];

结果如下:

CSDN移动问答

怎么变成这样呢。我希望图片能收缩和膨胀,而不是这样重画。

Csdn user default icon
上传中...
上传图片
插入图片