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...

  • 相关阅读:
    Ruby的一些基本知识
    Seleniumwebdriver系列教程(七)————如何处理alert和confirm
    Seleniumwebdriver系列教程(八)————如何操作select下拉框
    Ruby 控制结构
    Seleniumwebdriver系列教程(十)————使用jquery辅助进行测试
    Ruby是一门面向对象语言
    Seleniumwebdriver系列教程(九)————如何智能的等待页面加载完成
    Ruby 正则表达式
    执行ajax成功后进行页面的刷新
    Nacos介绍与安装启动
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5794481.html
Copyright © 2011-2022 走看看