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

CoreAnimation 核心动画

时间:2016-09-20 00:10:54      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

- (void)createBaseAnimation{

    //基础动画

    CABasicAnimation *animation = [CABasicAnimation animation];

    

    animation.keyPath = @"bounds";

//    animation.fromValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 300, 300)];//默认为现在的状态

    animation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 300, 300)];

    

    animation.duration = 2;

    animation.removedOnCompletion = NO//动画之后保持最新

    animation.fillMode = kCAFillModeForwards//最新样式

    

    animation.delegate = self;

    [view.layer addAnimation:animation forKey:nil];

 

}

 

- (void)animationDidStart:(CAAnimation *)anim{

    NSLog(@"动画开始时调用");

    

}

 

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{

    NSLog(@"动画结束时调用");

}

 

- (void)createKeyFrameAnimation{

    //帧动画

    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];

    animation.keyPath = @"position";

    //路径

//    CGMutablePathRef path = CGPathCreateMutable();

//    CGPathAddEllipseInRect(path, nil, CGRectMake(100, 100, 200, 200));

//    

//    animation.path = path;

    

//注意:与基础动画的区别:可以设置多个点/一堆值

    NSValue *value1 = [NSValue valueWithCGPoint:CGPointMake(0, 0)];

    NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake(0, 300)];

    NSValue *value3 = [NSValue valueWithCGPoint:CGPointMake(300, 0)];

    animation.values = @[value1,value2,value3];

    //动画的执行节奏

    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    animation.duration = 5;

    animation.removedOnCompletion = NO//动画之后保持最新

    animation.fillMode = kCAFillModeForwards//最新样式

    [view.layer addAnimation:animation forKey:nil];

    

}

 

- (void)createTransiton{

    //转场动画

    CATransition *animaiton = [CATransition animation];

    //动画过渡类型

    animaiton.type = @"cube";

    //过渡方向

    animaiton.subtype = kCATransitionFade;

    

    animaiton.duration = 3;

    [view.layer addAnimation:animaiton forKey:nil];

 

}

 

- (void)createAnimationGroup{

    //动画分组(旋转+缩放)

    //1.旋转

    CABasicAnimation *rotationAnimaiton = [CABasicAnimation animation];

    rotationAnimaiton.keyPath = @"transform.rotation.z";

    rotationAnimaiton.toValue = @(M_PI_4 * 3);

    rotationAnimaiton.duration = 5;

    rotationAnimaiton.repeatCount = MAXFLOAT;

    

    //2.缩放

    CABasicAnimation *scaleAnimation = [CABasicAnimation animation];

    scaleAnimation.keyPath = @"transform";

    scaleAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(2, 2, 0)];

    scaleAnimation.duration = 5;

    

    //动画分组

    CAAnimationGroup *group = [CAAnimationGroup animation];

    group.animations = @[rotationAnimaiton,scaleAnimation];

    group.removedOnCompletion = NO;

    group.fillMode = kCAFillModeForwards;

    group.duration = 5;

    [view.layer addAnimation:group forKey:nil];

    

}

 

 

 

 

 

CoreAnimation 核心动画

标签:

原文地址:http://www.cnblogs.com/daxueshan/p/5886905.html

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