美文网首页
ios UIButton一直旋转动画

ios UIButton一直旋转动画

作者: zxb有缘 | 来源:发表于2017-12-25 18:07 被阅读0次

    -(void)viewDidAppear:(BOOL)animated{
    ​ UIButton * buyBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 0, 50, 50)];
    [buyBtn setImage:[UIImage imageNamed:@"AppIcon40x40"] forState:UIControlStateNormal];
    [segmentView2 addSubview:buyBtn];
    buyBtn=[self rotate360DegreeWithImageView:buyBtn];
    }

    • (UIButton *)rotate360DegreeWithImageView:(UIButton *)imageView{

      CABasicAnimation *animation = [ CABasicAnimation animationWithKeyPath: @"transform" ];

      animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];

      //围绕Z轴旋转,垂直与屏幕

      animation.toValue = [ NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI/2.0, 0.0, 0.0, 1.0) ];

      animation.duration = 3;

      //旋转效果累计,先转180度,接着再旋转180度,从而实现360旋转

      animation.cumulative = YES;

      animation.repeatCount = MAXFLOAT;

      /*下面可以不需要
      CGRect imageRrect = CGRectMake(0, 0,imageView.imageView.frame.size.width, imageView.imageView.frame.size.height);
      UIGraphicsBeginImageContext(imageRrect.size);
      //在图片边缘添加一个像素的透明区域,去图片锯齿
      [imageView.currentImage drawInRect:CGRectMake(1,1,imageView.imageView.frame.size.width-2,imageView.imageView.frame.size.height-2)];
      [imageView setImage: UIGraphicsGetImageFromCurrentImageContext() forState:UIControlStateNormal];
      UIGraphicsEndImageContext();
      */
      [imageView.layer addAnimation:animation forKey:nil];

      return imageView;
      }

    相关文章

      网友评论

          本文标题:ios UIButton一直旋转动画

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