Some Taps You Don’t Want

UIButton is one of the most simple and commonly used UIControl. We use it so often in the way it is intended to be used that we dismiss it as a perfectly meek boy until one day it bites our fingers when we tap it.

Today is such a day.

I have a UIButton that when tapped will trigger a custom view transition with animations. Animations mean duration — it takes some time to complete. Though the transition is still in progress, the button does not refuse more taps — it just loves taps!

I guess you see the problem here: What happens if the button is tapped again during the view transition?

Another view transition is triggered, of course, and I don’t want it.

So I must filter out taps during the view transition.

Notice that you can’t reproduce this problem by double tapping a button that triggers a standard view transition such as pushing a view controller using -pushViewController:animated: or presenting a view controller using -presentViewController:animated:completion:. I guess it is because the view the button is on is being covered during these standard view transitions so the button can not receive taps.