美文网首页
IOS动画实现方式 - 旋转 - 放大

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

作者: 任梦RM | 来源:发表于2017-02-15 16:40 被阅读626次

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

    相关文章

      网友评论

          本文标题:IOS动画实现方式 - 旋转 - 放大

          本文链接:https://www.haomeiwen.com/subject/ncvqwttx.html