图标抖动

//
//  ViewController.m
//  图标抖动
//
//  Created by 陆巧怡 on 15/7/30.
//  Copyright (c) 2015年 Simon. All rights reserved.
//

#import "ViewController.h"
#define angle2Radian(angle) ((angle)/180.0 * M_PI)
@interface ViewController ()
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UIButton *button;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
    self.iconImageView.image = [UIImage imageNamed:@"newb"];
    [self.view addSubview:self.iconImageView];
    
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.button setTitle:@"停止" forState:UIControlStateNormal];
    self.button.frame = CGRectMake(200, 400, 100, 20);
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.button];
    
    
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    //创建核心动画
    CAKeyframeAnimation *keyAnima =[CAKeyframeAnimation animation];
    
    keyAnima.keyPath = @"transform.rotation";
    
    //弧度 = 度数/180 * M_PI
    
    keyAnima.values = @[@(-angle2Radian(4)),@(angle2Radian(4)),@(-angle2Radian(4))];
    
    
    //设置动画重复的次数
    keyAnima.repeatDuration = MAXFLOAT ;
    
    //执行完不删除动画
    keyAnima.removedOnCompletion = NO;
    //保持动画的最新状态
    keyAnima.fillMode = kCAFillModeForwards;
    keyAnima.duration = 0.3;
    
    //添加核心动画
    [self.iconImageView.layer addAnimation:keyAnima forKey:@"tingzhi"];
    
    
    
}

-(void)buttonAction:(UIButton *)btn{
    
    
    [self.iconImageView.layer removeAnimationForKey:@"tingzhi"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值