zoukankan      html  css  js  c++  java
  • iOS 实现UIImageView 的不停的旋转(更新:2017.7.26)

    1.先创建一个UIImageView.

    - (void)createImageView {
    
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0,0.0, frame.size.width, frame.size.height)];
    
        imageView.image = [UIImageimageNamed:@"image1.png"];
    
        self.myImageView = imageView;
    
        [self addSubview:imageView];
    
    }

     

    问题:方法一二是让iamgeview 循环旋转角度,如果把imageview 放在tableviewcell上边,每次刷新tableview,imageview 的旋转速度会加倍;没有去做相应的处理,而是直接利用另一个旋转方法三

    方法三:

     CABasicAnimation *animation =  [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        //默认是顺时针效果,若将fromValue和toValue的值互换,则为逆时针效果
        animation.fromValue = [NSNumber numberWithFloat:0.f];
        animation.toValue =  [NSNumber numberWithFloat: M_PI *2];
        animation.duration  = 1;
        animation.autoreverses = NO;
        animation.fillMode =kCAFillModeForwards;
        animation.repeatCount = MAXFLOAT; //如果这里想设置成一直自旋转,可以设置为MAXFLOAT,否则设置具体的数值则代表执行多少次
        [self.imageView1.layer addAnimation:animation forKey:nil];

     

    //方法一:

    - (void)buttonAction:(id)sender {
    
        angle = 0.0;
    
        [selfstartAnimation];
    
    }
    
    - (void)startAnimation
    
    {
    
        [UIView beginAnimations:nilcontext:nil];
    
        [UIView setAnimationDuration:0.01];
    
        [UIView setAnimationDelegate:self];
    
        [UIView setAnimationDidStopSelector:@selector(endAnimation)];
    
        self.myImageView.transform = CGAffineTransformMakeRotation(angle * (M_PI /180.0f));
    
        [UIView commitAnimations];
    
    }
    
    -(void)endAnimation
    
    {
    
        angle += 15;
    
        [selfstartAnimation];
    
    }
    方法一

     

    //方法二:(使用Block)

    - (void)startAnimation
    
    {
    
        CGAffineTransform endAngle = CGAffineTransformMakeRotation(angle * (M_PI /180.0f));
    
        [UIView animateWithDuration:0.01delay:0 options:UIViewAnimationOptionCurveLinearanimations:^{
    
            self.myImageView.transform = endAngle;
    
        } completion:^(BOOL finished) {
    
            angle += 15;
    
            [selfstartAnimation];        
    
        }];
    
    }
  • 相关阅读:
    关于在php+apache开发过程中使用svn进行版本的维护
    Fragment的切换动画实现
    IOS MJExtension json转模型的轻量级框架的使用
    Centos 配置Red5流媒体服务器
    在Centos 6.5 上面配置 SVN
    在Centos 上面配置Openfire
    关于阿里云上面的Centos上面配置 防火墙
    【Android 一些难以理解的控件、容易混淆的、多种实现方式的、一些该纠正的想法】
    【进攻移动开发_htm5_跨平台_的号角】
    【进攻Android的号角】
  • 原文地址:https://www.cnblogs.com/xujiahui/p/6611043.html
Copyright © 2011-2022 走看看