做过一个项目,里面涉及到的动画效果比较多,在这里做个小小的总结。
直线动画效果
实现一个物体在某段时间从一个点移动到另一个点。
效果如下:
动画相关代码如下:
动画模型:
@interface AnimationModel : NSObject
@property(nonatomic,strong) NSArray * images;
@property(nonatomic,assign) float fromX;
@property(nonatomic,assign) float fromY;
@property(nonatomic,assign) float toX;
@property(nonatomic,assign) float toY;
@property(nonatomic,assign) BOOL loop;
@property(nonatomic,assign) float time;
@end
动画实现:
-(void)addSingleLineAnimationToView:(UIView *)view animationModel:(AnimationModel *)model{
CABasicAnimation* moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
moveAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(model.fromX,model.fromY)];
moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(model.toX,model.toY)];
moveAnimation.duration = model.time;
moveAnimation.removedOnCompletion = NO;
moveAnimation.repeatCount = MAXFLOAT;
if (model.loop == 0) {
moveAnimation.repeatCount = 1;
}
[view.layer addAnimation:moveAnimation forKey:@"singleLineAnimation"];
}
爆炸点赞动画效果
效果有点像撒花,效果如下:
这个效果的实现也是我在网上找到的,封装了一个View和一个button,调用很方便,下面我贴一下调用的代码,后面会给出完整代码的地址。
调用代码&#x