抖动代码
//
// ViewController.m
// 01-抖动
//
// Created by Lenny on 3/16/15.
// Copyright (c) 2015 Lenny. All rights reserved.
//
#import "ViewController.h"
#define angle2Radian(angle) ((angle) / 180.0 * M_PI)
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *imageView;
@end
@implementation ViewController
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
// 1.创建核心动画
CAKeyframeAnimation * kfr = [[CAKeyframeAnimation alloc]init];
// 2.创建核心动画的类型
kfr.keyPath = @"transform.rotation";
// 度数/ 180.0 *M_PI
kfr.values = @[@(-angle2Radian(4)), @(angle2Radian(4)), @(-angle2Radian(4))];
kfr.removedOnCompletion = NO;
kfr.fillMode = kCAFillModeBackwards;
kfr.duration = 0.1;
// 设置重复次数
kfr.repeatCount = MAXFLOAT;
// 3添加核心动画
[self.imageView.layer addAnimation:kfr forKey:nil];
}
@end