I\'m trying to find a way to consume a button press, not from the response chain per se, but from other action methods bound to that button. I\'ve looked all over for this
Based on the @danielquokka idea about override the method sendActionsForControlEvents:
, I subclass UIButton and add following codes. It works fine. After firing event, it will block UI events for 0.5 seconds.
- (void)sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event
{
[super sendAction:action to:target forEvent:event];
self.userInteractionEnabled = NO;
///! After handle UIEvent, block this button UI events for a while.
[self performSelector:@selector(delayEnable) withObject:nil afterDelay:0.5];
}
- (void)delayEnable
{
self.userInteractionEnabled = YES;
}
Another way to ignore UI events is by [[UIApplication sharedApplication] beginIgnoringInteractionEvents]
and [[UIApplication sharedApplication] endIgnoringInteractionEvents]
.
beginIgnoringInteractionEvents
and endIgnoringInteractionEvents
will block all touch events for the Application until endIgnoringInteractionEvents
called.
if you know the current state of the app like tutorial etc then probably better to use only one handler1. And add to the body of the method handler1: if (mode == tutorial) {tutorial} else {default}.
You may be able to add a category to UIButton (or subclass it), overriding the method sendActionsForControlEvents: to only call sendAction:to:forEvent: for one target (refer to the documentation on UIControl for descriptions of those methods).