码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 一些简单动画

时间:2015-07-03 12:09:13      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

    1.旋转动画

    CABasicAnimation* rotationAnimation;

    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];

    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    rotationAnimation.duration = 2;

    rotationAnimation.repeatCount = 1000;//你可以设置到最大的整数值

    rotationAnimation.cumulative = NO;

    

    rotationAnimation.removedOnCompletion = NO;

    rotationAnimation.fillMode = kCAFillModeForwards;

    

    [self.image.layer addAnimation:rotationAnimation forKey:@"Rotation"];

 

    2.缩放动画

    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

    scaleAnimation.fromValue = [NSNumber numberWithFloat:0.0];

    scaleAnimation.toValue = [NSNumber numberWithFloat:1.0];

    scaleAnimation.duration = 1.0f;

    scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    

    scaleAnimation.removedOnCompletion = NO;

    scaleAnimation.fillMode = kCAFillModeForwards;

    

    [self.image.layer addAnimation:scaleAnimation forKey:@"Scale"];

 

    3.透明度变化

    CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];

    opacityAnimation.fromValue = [NSNumber numberWithFloat:1];

    opacityAnimation.toValue = [NSNumber numberWithFloat:0];

    opacityAnimation.duration = 2.0f;

 

    opacityAnimation.removedOnCompletion = NO;

    opacityAnimation.fillMode = kCAFillModeForwards;

    

    [self.image.layer addAnimation:opacityAnimation forKey:@"opacity"];

 

    4.创建动画组,把动画放在一个组里展示

    CAAnimationGroup *animationGroup = [CAAnimationGroup animation];

    animationGroup.duration = 2.0f;

    animationGroup.autoreverses = YES;   //是否重播,原动画的倒播

    animationGroup.repeatCount = NSNotFound;//HUGE_VALF;     //HUGE_VALF,源自math.h

    [animationGroup setAnimations:[NSArray arrayWithObjects:rotationAnimation, scaleAnimation, opacityAnimation,nil]];

 

iOS 一些简单动画

标签:

原文地址:http://www.cnblogs.com/tongyuling/p/4617982.html

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