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

iOS学习笔记28-基础动画和关键帧动画

时间:2016-02-27 13:50:15      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

首先创建layer

  CALayer *layer = [CALayer layer];

    

    layer.bounds = CGRectMake(0, 0, 100, 100);

    layer.position = CGPointMake(100, 100);

    layer.backgroundColor = [UIColor yellowColor].CGColor;

    [self.view.layer addSublayer:layer];

    self.layer = layer;

 

 

 

设置点击事件

 

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

//    [self animationScale];

    [self keyAnimation];

 

}

 

 

 

缩小动画

 

-(void)animationScale{

    CABasicAnimation *anim = [CABasicAnimation animation];

    //2设置动画

//    anim.keyPath = @"bounds";//平移

//    anim.keyPath = @"position";//缩放

    anim.keyPath =@"transform";

    //到达哪个点

//    anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 50, 50)];

//    anim.toValue = [NSValue valueWithCGPoint:CGPointMake(300,300)];

    

    anim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 1, 1, 0)];

    anim.duration = 2;

    anim.removedOnCompletion = NO;

    anim.fillMode = @"forwards";

    [self.layer addAnimation:anim forKey:nil];

 

 

 

}

 

 

 

-(void)keyAnimation

{

    CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];

    anim.removedOnCompletion = NO;

    anim.fillMode = kCAFillModeForwards;

    anim.duration = 2;

    CGMutablePathRef path = CGPathCreateMutable();

    CGPathAddEllipseInRect(path, NULL, CGRectMake(100, 100, 200, 200));

    anim.path = path;

    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

    [self.layer addAnimation:anim forKey:nil];

}

 

iOS学习笔记28-基础动画和关键帧动画

标签:

原文地址:http://www.cnblogs.com/adodo/p/5222760.html

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