Search code examples
objective-cioscocoa-touchuibuttoncore-animation

Start an action with a button when one is already going on


When I click a UIButton, say b1, two random values, x and y, are generated which become the new coordinates of another UIButton, say b2. b2 slowly moves to the required position (using +[UIView animateWithDuration: animations:] ). Now what I want to happen is: while b2 is in motion, clicking b1 again should move b2 to the new coordinates. What's happening right now is that I'm unable to click on b1 until b2 is nicely settled in the generated position. Any insights?


Solution

  • You'll want to use

    + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
    

    instead. And set UIViewAnimationOptionAllowUserInteraction in the options so that iOS doesn't block user interaction when the animation is occurring.

    You'll also want to set UIViewAnimationOptionBeginFromCurrentState so that the button begins at the current state.