BasicAnimation

2018-06-15  本文已影响3人  William_

1、位移动画

CABasicAnimation *ani = [CABasicAnimation animation];
    ani.keyPath = @"position.x";
    ani.fromValue = @77;
    ani.toValue = @455;
    ani.duration = 1;
    
    ani.fillMode = kCAFillModeForwards;
//    ani.removedOnCompletion = NO;

    [img1.layer addAnimation:ani forKey:@"basic"];
    img1.layer.position = CGPointMake(300, 61);

    ani.beginTime = CACurrentMediaTime() + 1.0;
    [self.img2.layer addAnimation:ani forKey:@"basic"];
    self.img2.layer.position = CGPointMake(300, 120);

2、抖动(输入框)

CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
    animation.keyPath = @"position.x";
    animation.values = @[@0, @10, @-10, @10, @0];
    animation.keyTimes = @[@0, @(1/6.0), @(3/6.0), @(5/6.0), @1];
    animation.duration = 0.4;
    animation.additive = YES;
    [self.tf1.layer addAnimation:animation forKey:@"shake"];

3、简单KeyframeAnimation旋转

CALayer *layer1 = [CALayer layer];
    layer1.backgroundColor = [UIColor brownColor].CGColor;
    layer1.frame = CGRectMake(50, 200, 50, 50);
    [self.view.layer addSublayer:layer1];
    
    CGRect boundingRect = CGRectMake(-150, -150, 300, 300);
    CAKeyframeAnimation *orbit = [CAKeyframeAnimation animation];
    orbit.keyPath = @"position";
    orbit.path = CFAutorelease(CGPathCreateWithEllipseInRect(boundingRect, NULL));
    orbit.duration = 4;
    orbit.additive = YES;
    orbit.repeatCount = HUGE_VALF;
    orbit.calculationMode = kCAAnimationPaced;
    orbit.rotationMode = kCAAnimationRotateAuto;
    
    [layer1 addAnimation:orbit forKey:@"orbit"];

4、Transition

按钮
sender.selected = !sender.selected;
    
    if (sender.selected) {
        [UIView animateWithDuration:2.0 animations:^{
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.img3 cache:YES];
            [self.img3 setImage:[UIImage imageNamed:@"MYR"]];
        }];
    } else {
        [UIView animateWithDuration:2.0 animations:^{
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.img3 cache:YES];
            [self.img3 setImage:[UIImage imageNamed:@"image1"]];
        }];
    }
上一篇下一篇

猜你喜欢

热点阅读