UIButton receives touches at the wrong position after CABasicAnimaton applied

Posted by Dmitry on Stack Overflow See other posts from Stack Overflow or by Dmitry
Published on 2012-12-19T17:02:27Z Indexed on 2012/12/19 17:02 UTC
Read the original article Hit count: 253

Filed under:
|
|
|
|

I need to add an animation to UIButton - simple moving animation. When I do this, the button moves, but the click area of that button remains at old position:

UIButton *slideButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[slideButton addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
[slideButton setFrame:CGRectMake(50, 50, 50, 50)];
[self.view addSubview:slideButton];

CABasicAnimation *slideAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
[slideAnimation setRemovedOnCompletion:NO];
[slideAnimation setDuration:1];
[slideAnimation setFillMode:kCAFillModeBoth];
[slideAnimation setAutoreverses:NO];

slideAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(50, 50)];
slideAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
[slideButton.layer addAnimation:slideAnimation forKey:@"slide"];

I already saw an answer to change the frame of the button at the end of the animation (like here UIButton receives touchEvents at the wrong position after a CABasicAnimaton) But it's not my case because I should give possibility to user to click on the button while it's moving... Also, I can't use another approaches (like NSTimer) as a replacement for CABasicAnimation because I will have a complex path to move the object...

Thanks for Your help!

© Stack Overflow or respective owner

Related posts about ios

Related posts about events