Question

UI animations are great, very easy to use, and are used allot. The only one problem I have with it is that while the animation is moving, the view in not receiving any user interaction.

For example, if a have a UIButton that animates every time it's shown, but the user will not be able to click on it until the animation is over.

//This is a UIButton:

- (void)animationApear
{
     CGRect frameSelf = self.frame;
     frameSelf.origin.y -= frameSelf.size.height;

     [UIView animateWithDuration:1.0 delay:0
          usingSpringWithDamping:0.8 initialSpringVelocity:0
                         options:0
                      animations:^{

                        [self setFrame:frameSelf];

                    } completion:nil];
}

Is there any way to deal with this issue?

Thanks!

Was it helpful?

Solution

You need to supply the option UIViewAnimationOptionAllowUserInteraction.

OTHER TIPS

Also, depending on your view architecture, if the button is within the animated view, or a subview thereof, then the actual location of the button isn't moving. Only the presentation layer of the button is moving, so that is why the button may not be receiving taps. A good test is to tap where the button was when the animation started (and make sure the option UIViewAnimationOptionAllowUserInteraction is on) to see if it is still receiving taps.

On solution, when you actually need to animate buttons, is to make repeated short transforms (CGAffineTransforms, for example) and have those movements in aggregate, create the visual effect of the animation. Though in this case the button itself will move, rather than simply it's presentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top