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

  • 相关阅读:
    用 Flash 制作留言板
    解决IIS5 HTTP500内部错误
    人体塑造教程+源文件+录象教程
    sql溢出攻击
    美化windows xp 完全教程
    简单手绘背景绘画过程树!
    今天把伊苏6 玩潼关了!庆祝一下!发点图给大家欣赏。
    Rundll.exe 命令详解
    终端服务的日志监控
    用Visual C#实现局域网点对点通讯
  • 原文地址:https://www.cnblogs.com/LzwBlog/p/5794481.html
Copyright © 2011-2022 走看看