UIButton 的layer 在加入动画之后,点击事件就失效了
以下是我的代码, 这里的btn在没有加入动画的时候,click是可以使用的,但是加入了 animation之后,btn在移动的时候,点击事件没有触发click函数。请问应该怎么样才能触发click。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor grayColor];
UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 50, 50)];
[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchDown];
btn.layer.cornerRadius = 25;
btn.backgroundColor = [UIColor whiteColor];
[self.view addSubview:btn];
UIBezierPath * path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(240, 160) radius:100 startAngle:(0/180.0)*M_PI endAngle:((0-1)/(180.0))*M_PI clockwise:YES];
CAKeyframeAnimation *orbit = [CAKeyframeAnimation animationWithKeyPath:@"position"];
orbit.path = path.CGPath;
orbit.duration = 16;
orbit.repeatCount = HUGE_VALF;
[btn.layer addAnimation:orbit forKey:@"orbit"];
}
-(void)click
{
NSLog(@"click");
}