第二十九篇CoreAnimation的使用
Posted 久冬不雨
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第二十九篇CoreAnimation的使用相关的知识,希望对你有一定的参考价值。
使用的的三个步骤
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];
以上是关于第二十九篇CoreAnimation的使用的主要内容,如果未能解决你的问题,请参考以下文章