2019-03-07

核心动画

1.隐式动画

 [CATransaction begin];//开启事务

    [CATransaction setDisableActions:YES];

    self.layer.position=CGPointMake(200,200);

    self.layer.backgroundColor = [UIColor redColor].CGColor;                      self.layer.bounds=CGRectMake(0,0,200,200);

    [CATransaction commit];//提交事务

2.帧动画(抖动动画)

CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];

    anim.keyPath = @"transform.rotation";

    anim.values = @[@(AngleToRadian(-5)), @(AngleToRadian(5)), @(AngleToRadian(-5))];

    anim.duration=0.15;

    anim.removedOnCompletion = NO;

    anim.fillMode = kCAFillModeForwards;

    anim.repeatCount=MAXFLOAT;

    [self.iconView.layer addAnimation:anim forKey:@"shake"];

3.帧动画平移动画

CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];

    anim.keyPath=@"position";

    anim.duration=2.0;

    anim.removedOnCompletion = NO;

    anim.fillMode = kCAFillModeForwards;

    CGMutablePathRef path = CGPathCreateMutable();

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

    anim.path= path;

    CGPathRelease(path);

    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    anim.delegate=self;

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

4.动画组

CABasicAnimation *rotate = [CABasicAnimation animation];

    rotate.keyPath = @"transform.rotation";

    rotate.toValue=@(M_PI);


    CABasicAnimation *scale = [CABasicAnimation animation];

    scale.keyPath = @"transform.scale";

    scale.toValue=@(0);


    CABasicAnimation *transform = [CABasicAnimation animation];

    transform.keyPath = @"transform.translation";

    transform.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];


    group.animations=@[rotate, scale, transform];

    group.duration=5.0;

    group.removedOnCompletion = YES;

    group.fillMode = kCAFillModeForwards;


    [self.redView.layer addAnimation:group forKey:nil];


©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 如果想让事情变得顺利,只有靠自己--夏尔·纪尧姆 上一章介绍了隐式动画的概念。隐式动画是在iOS平台创建动态用户界...
    夜空下最亮的亮点阅读 2,098评论 0 1
  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 3,321评论 1 23
  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。下面我们逐个介绍。...
    4b5cb36a2ee2阅读 433评论 0 0
  • 1 CALayer IOS SDK详解之CALayer(一) http://doc.okbase.net/Hell...
    Kevin_Junbaozi阅读 5,336评论 3 23
  • 显式动画 显式动画,它能够对一些属性做指定的自定义动画,或者创建非线性动画,比如沿着任意一条曲线移动。 属性动画 ...
    清风沐沐阅读 2,093评论 1 5

友情链接更多精彩内容