I need to disable all user interactions with other ui elements immediately after the user taps on a button. I want to prevent the user from triggering multiple actions at once, for example pressing a button and tap on an element in a collection view or a tap on a UIBackBarButton.
So as an example I created a UIBarButtonItem that calls this method, that disables user interactions of self.view and the UIBarButtonItems and re-enables them again after 1 second:
- (void)buttonPressed:(id)sender
{
self.view.userInteractionEnabled = NO;
self.navigationItem.backBarButtonItem.enabled = NO;
self.navigationItem.rightBarButtonItem.enabled = NO;
// ... show an alert view
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
self.view.userInteractionEnabled = YES;
self.navigationItem.backBarButtonItem.enabled = YES;
self.navigationItem.rightBarButtonItem.enabled = YES;
});
}
The problem is, that if I tap this button and for example the back button almost simultaneously, it shows the alert view and pops the current viewController. I assume, that it waits a few milliseconds to determine, if this event is a single touch or multiple touch event (e.g. double tap), but I couldn't figure out how to handle this.
What can I do to disable the user interactions immediately after the user tapped this button?