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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS学习笔记28-基础动画和关键帧动画相关的知识,希望对你有一定的参考价值。

首先创建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 [email protected]"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-基础动画和关键帧动画的主要内容,如果未能解决你的问题,请参考以下文章

AE学习笔记——第三章:动画制作基础1

动画基础,3种动画方式

iOS CoreAnimation 关键帧动画 CAKeyframeAnimation

ios核心动画之关键帧动画

iOS开发UI篇—核心动画(关键帧动画)

WPF关键帧动画