IOS动画实现方式 - 旋转 - 放大

2017-02-15  本文已影响626人  任梦RM

1.旋转

    CABasicAnimation *animation =  [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    //默认是顺时针效果,若将fromValue和toValue的值互换,则为逆时针效果
    animation.fromValue = [NSNumber numberWithFloat:M_PI *2];
    animation.toValue =  [NSNumber numberWithFloat: 0.f];
    animation.duration  = 1.5;                  //一次时间
    animation.autoreverses = NO;                         //是否自动回倒
    animation.fillMode =kCAFillModeForwards;
    animation.removedOnCompletion = NO;           //设置进入后台动画不停止
    animation.repeatCount = CGFLOAT_MAX ;            //重复次数
    animation.delegate = self;                    //动画代理
    [gifImageView.layer addAnimation:animation forKey:nil];

2.放大

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animation.toValue = [NSNumber numberWithFloat:1.5f];
    CABasicAnimation *ani1 = [CABasicAnimation animationWithKeyPath:@"opacity"];
    ani1.toValue = [NSNumber numberWithFloat:0.1f];
    
    CAAnimationGroup *anGroup = [CAAnimationGroup animation];
    anGroup.animations = @[animation,ani1];
    anGroup.duration = 1.f;
    anGroup.autoreverses = NO;
    anGroup.repeatCount = CGFLOAT_MAX;
    anGroup.removedOnCompletion = NO; //设置进入后台动画不停止
    [imageView1.layer addAnimation:anGroup forKey:@"a"];
    [UIView animateWithDuration:0.5 animations:^{
        imageView2.alpha = 1.0f;
    }completion:^(BOOL finished) {
        [imageView2.layer addAnimation:anGroup forKey:@"b"];
    }];
上一篇下一篇

猜你喜欢

热点阅读