4

I want to move a UIButton with animation, and while its moving if user touches it, I want recognized that event, but during animation UIButton doesn't sent any event.

Please solve my problem.

Rais
  • 95
  • 6
  • possible duplicate of [UIButton can't be touched while animated with UIView animateWithDuration](http://stackoverflow.com/questions/8346100/uibutton-cant-be-touched-while-animated-with-uiview-animatewithduration) – leekaiinthesky May 12 '15 at 13:53

3 Answers3

8

Have you tried AllowUserInteraction option?

 [UIView animateWithDuration:5.0 
                       delay:0.0         
                     options:UIViewAnimationOptionAllowUserInteraction
                  animations:^{ // move the button }
                 completion:^(BOOL finished){}];
danh
  • 62,181
  • 10
  • 95
  • 136
1

During an animation, user interactions are temporarily disabled for all views involved in the animation, regardless of the value in this property. You can disable this behavior by specifying the UIViewAnimationOptionAllowUserInteraction option when configuring the animation.

Also, you can implement

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

in the superview to catch the event and see if the event is pointing to the button.

khose
  • 743
  • 1
  • 6
  • 19
0

As UIButton inherit from UIControl which inherit UIView, I believe you are using the block based method to animate your button animateWithDuration:delay:options:animations:completion:

You will need to add the option UIViewAnimationOptionAllowUserInteraction when you animate your UIButton to allow to recognize some user interaction. As you experimented user interaction are by default disabled during the animation otherwise.

tiguero
  • 11,477
  • 5
  • 43
  • 61