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

CAniamtion练习

时间:2015-06-29 20:13:05      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:

//渐变
    UIButton *b = (UIButton *)sender;
    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromRight;
    [self.imageview.layer addAnimation:transition forKey:@"transition"];
    self.imageview.image = [UIImage imageNamed:@"avatar.jpg"];
    
    //基本
    CABasicAnimation *baseProperty = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    baseProperty.fromValue = [NSNumber numberWithDouble:1.0];
    baseProperty.toValue = [NSNumber numberWithDouble:0.4];
    baseProperty.duration = 1.0;
    baseProperty.removedOnCompletion = NO;
    baseProperty.fillMode = kCAFillModeForwards;
    baseProperty.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    [self.imageview.layer addAnimation:baseProperty forKey:@"baseProperty"];
    
    //关键帧
    //动画组
    CAKeyframeAnimation *keyFrameAniamtion = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    
    CGMutablePathRef mutablePath = CGPathCreateMutable();
    CGPathMoveToPoint(mutablePath, NULL, self.imageview.frame.origin.x, self.imageview.frame.origin.y);
    CGPathAddLineToPoint(mutablePath, NULL, 0, 0);
    keyFrameAniamtion.path = mutablePath;
    
    keyFrameAniamtion.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    
    CAKeyframeAnimation *keyframe2 = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
    NSArray *values2 = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0], [NSNumber numberWithFloat:(M_PI * 10)], nil];
    keyframe2.values = values2;
    keyframe2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.removedOnCompletion = NO;
    group.fillMode = kCAFillModeForwards;
    group.animations = [NSArray arrayWithObjects:keyFrameAniamtion, keyframe2, nil];
    group.duration = 2.0;
    [self.imageview.layer addAnimation:group forKey:@"group"];

 

CAniamtion练习

标签:

原文地址:http://www.cnblogs.com/apem/p/4608196.html

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