码迷,mamicode.com
首页 > 其他好文 > 详细

第二十九篇、CoreAnimation的使用

时间:2016-09-17 23:45:36      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:

使用的的三个步骤

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的使用

标签:

原文地址:http://www.cnblogs.com/HJQ2016/p/5879969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!