IPhone development: disabling user interaction during animation

In my application, I have an animation. for example, I have a button in the main menu, and when you click on it, the animation starts (for example, moving a place, etc.), and at the end of the animation it goes to another page. I need to disable user interaction during animation. because during the animation. If I click on the start point of my button, the page that needs to be moved opens twice. To summarize, if I don't allow any user interaction during the animation, my problem will be solved. How can i do this?

+8
ios objective-c iphone animation user-interaction
source share
8 answers

Before animation:

self.view.userInteractionEnabled = NO; 

and in the animation completion block:

 self.view.userInteractionEnabled = YES; 
+19
source share

This can help:

 // for ignoring event [[UIApplication sharedApplication] beginIgnoringInteractionEvents]; [[UIApplication sharedApplication] endIgnoringInteractionEvents]; 

The code will look like this:

 [UIView animateWithDuration:1.0 animations:^{ //some animation [[UIApplication sharedApplication] beginIgnoringInteractionEvents]; } completion:^(BOOL done){ if (done){ [[UIApplication sharedApplication] endIgnoringInteractionEvents]; } } ]; 
+15
source share

Simple, you can set setUserInteractionEnabled to NO before starting the animation, and in the animation completion handler, set it to YES .

 [myObject setUserInteractionEnabled:NO]; [UIView animateWithDuration:1.0 animations:^{ [myObject setTransform:CGAffineTransformMakeTranslation(100, 100)];//some animation }completion:^(BOOL done){ if (done){ [myObject setUserInteractionEnabled:YES]; } }]; 
+6
source share

You do not need to hack the completion block - there is an animation option that does just that:

 [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ // animations here } completion:nil]; 

If you set UIViewAnimationOptionAllowUserInteraction , then user interaction would be allowed.

+5
source share
 yourView.userInteractionEnabled = NO; [UIView animateWithDuration:1 animations:^ { //animations here } completion:^(BOOL finished) { yourView.userInteractionEnabled = YES; }]; 
+2
source share

To disable a touch event in a view,

  [[UIApplication sharedApplication] beginIgnoringInteractionEvents]; 

To enable a touch event in a view

 [[UIApplication sharedApplication] endIgnoringInteractionEvents]; 
+2
source share

Disable button customization.

 Btn.userInteractionEnabled = NO; 
+1
source share

I had a view controller with icons that open pages. If the user quickly clicked icon1 and icon2, 2 pages opened.

to prevent that I had these 2 lines before the start of the tap event, make sure that everything happens, endIgnoring will call

 -(void) on_image_tap:(UITapGestureRecognizer * ) tapGesture { [[UIApplication sharedApplication] beginIgnoringInteractionEvents]; [[UIApplication sharedApplication] performSelector:@selector(endIgnoringInteractionEvents) withObject:nil afterDelay:0.5f]; 
0
source share

All Articles