#import "ViewController.h"
#define angelToRandian(x) ((x)/180.0*M_PI)
@interface ViewController ()
{
UIView *view;
}
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor =[UIColor redColor];
view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
view.backgroundColor=[UIColor yellowColor];
[self.view addSubview:view];
UILongPressGestureRecognizer* longPress=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
[view addGestureRecognizer:longPress];
}
-(void)longPress:(UILongPressGestureRecognizer*)longPress
{
if (longPress.state==UIGestureRecognizerStateBegan) {
CAKeyframeAnimation* anim=[CAKeyframeAnimation animation];
anim.keyPath=@"transform.rotation";
anim.values=@[@(angelToRandian(-7)),@(angelToRandian(7)),@(angelToRandian(-7))];
anim.repeatCount=MAXFLOAT;
anim.duration=0.2;
[view.layer addAnimation:anim forKey:nil];
// self.btn.hidden=NO;
}
}