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];


你可能感兴趣的:(2019-03-07)