标签:
使用的的三个步骤
1.初始化演员
2.设置好剧情
3.播放
附录:一个把商品添加到购物车的抛物线动画
coreAnimation // 1.初始化演员 CALayer *layer = [[CALayer alloc]init]; layer.bounds = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); layer.position = CGPointMake(160, 160); // 设置内容 //layer.contents = (id)_imageViewBtn.imageView.image.CGImage [self.view.layer addSublayer:layer]; // 2.设定剧情 // 贝尔曲线 UIBezierPath *movePath = [UIBezierPath bezierPath]; [movePath moveToPoint:layer.position]; [movePath addQuadCurveToPoint:CGPointMake(319, [UIScreen mainScreen].bounds.size.height - 45 - 20) controlPoint:CGPointMake(0,0)]; // 关键帧 CAKeyframeAnimation *positionnAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; positionnAnimation.path = movePath.CGPath; positionnAnimation.removedOnCompletion = YES; // 基本动画(缩放) CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.sale"]; scaleAnimation.fromValue = @1; scaleAnimation.toValue = @.025; scaleAnimation.duration = .8f; scaleAnimation.autoreverses = NO; scaleAnimation.repeatCount = 1; // 防止动画闪烁 scaleAnimation.removedOnCompletion = NO; scaleAnimation.fillMode = kCAFillModeForwards; scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; // 组动画 CAAnimationGroup *animationGroup = [CAAnimationGroup animation]; animationGroup.duration = 0.8f; animationGroup.autoreverses = NO; animationGroup.repeatCount = 1; animationGroup.repeatDuration = NO; animationGroup.fillMode = kCAFillModeForwards; [animationGroup setAnimations:[NSArray arrayWithObjects:positionnAnimation,scaleAnimation, nil]]; // 3.播放 [layer addAnimation:animationGroup forKey:nil];
标签:
原文地址:http://www.cnblogs.com/HJQ2016/p/5879969.html