zoukankan      html  css  js  c++  java
  • UI--图标抖动动画

    图片左右抖动动画,一张图片,二个按钮,开始和暂停

    直接上代码:

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @property (nonatomic, strong) UIImageView *imgIOY;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
        imageV.backgroundColor = [UIColor yellowColor];
        imageV.image = [UIImage imageNamed:@"lian"];
        imageV.clipsToBounds = YES;
        imageV.layer.cornerRadius = 50;
        [self.view addSubview:imageV];
        self.imgIOY = imageV;
        
        UIButton *btnStart = [UIButton buttonWithType:UIButtonTypeCustom];
        btnStart.backgroundColor = [UIColor purpleColor];
        btnStart.frame = CGRectMake(100, 300, 150, 30);
        [btnStart setTitle:@"开始" forState:UIControlStateNormal];
        [self.view addSubview:btnStart];
        [btnStart addTarget:self action:@selector(btnStart:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *btnStop = [UIButton buttonWithType:UIButtonTypeCustom];
        btnStop.backgroundColor = [UIColor purpleColor];
        btnStop.frame = CGRectMake(100, 400, 150, 30);
        [btnStop setTitle:@"结束" forState:UIControlStateNormal];
        [self.view addSubview:btnStop];
        [btnStop addTarget:self action:@selector(btnStop:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    - (void)btnStart:(UIButton *)btnStart{
        NSLog(@"动画开始");
        
        CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
        
        
        anim.keyPath = @"transform.rotation";
        
        anim.values = @[@(0), @(-5 * M_PI/180), @(0), @(5 * M_PI/180), @(0)];
        
        anim.repeatCount = MAXFLOAT;
        
        anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
        
        anim.duration = 0.2;
        
        [self.imgIOY.layer addAnimation:anim forKey:@"dou"];
        
    }
    
    - (void)btnStop:(UIButton *)btnStop{
        NSLog(@"动画结束");
        [self.imgIOY.layer removeAnimationForKey:@"dou"];
    
    }
    
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end

    OK...

  • 相关阅读:
    【转载】浏览器兼容性测试
    【转载】移动端
    【转载】Postman学习之【压力测试】
    【转载】如何进行bug总结
    【转载】按键精灵对安卓APP进行自动化界面点击测试
    【转载】Selenium+Python自动化测试环境搭建和搭建过程遇到的问题解决
    【转载】fiddler软件测试——Fiddler抓取https设置详解(图文)
    【转载】服务器性能测试工具 ---- nmon
    python中的一些好用的库
    python操作excel表格相关的库
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5794481.html
Copyright © 2011-2022 走看看