Xcode中可以使用CABasicAnimation类实现动画效果
CABasicAnimation *strokeAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
strokeAnimation.fromValue = @0.0;
strokeAnimation.toValue = @1.0;
strokeAnimation.duration = 2;
animationWithKeyPath的参数是字符串,特定的KeyPath字符串表示特定的动画效果
动画效果的参数由fromValue、toValue、beginpath、duration等属性改变,在不同的KeyPath下有不同的意义
在以上代码的例子中,KeyPath为@“strokeEnd”,其效果为沿路径绘制,fromValue和toValue分别代表起始位置和终止位置,有效区间为0(fromValue)-1(toValue),duration为动画速度,1为正常,数值越大速度越慢
动画的路径可以由(NS/UI)BezierPath实现
@property (strong, nonatomic) UIBezierPath *FullPath;
self.path = self.FullPath.CGPath; //这里调用路径
-(UIBezierPath *) FullPath {
if(!_FullPath){
_FullPath = [[UIBezierPath alloc] init];
[_FullPath moveToPoint:CGPointMake(0.0, 100.0)];
[_FullPathaddLineToPoint:CGPointMake(0.0, -KLineWidth)];
[_FullPath addLineToPoint:CGPointMake(100.0, -KLineWidth)];
[_FullPath addLineToPoint:CGPointMake(100.0, 100.0)];
[_FullPath addLineToPoint:CGPointMake(-KLineWidth / 2, 100.0)];
[_FullPath closePath];
}
return _FullPath;
}