Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IBAction UIButton firing is delayed

I have a UIButton connected to an IBAction in Interface Builder.

The Problem:

  • The action firing and the de-highlight of the button both take a little bit to happen.

The Facts:

  • View structure:
    • View
      • 10 Buttons (connected via UIControlEventTouchUpInside to the IBAction
      • View (Subview)
        • Gesture recognizer
        • Text Field
  • The Subview has a UITapGestureRecognizer, which delaysTouchesBegan and delaysTouchesEnded both are set to NO
  • The action is happening in the main thread.
  • Testing a simple button (with no images or title, and only a simple NSLog), the result is the same

The Question: Why are firing and the de-highlight delayed?

like image 689
Natan R. Avatar asked May 10 '12 09:05

Natan R.


2 Answers

In the end, I added somewhere some UIGestureRecognizer, and forgot to set delaysTouchesBegan to NO =(

like image 132
Natan R. Avatar answered Nov 10 '22 16:11

Natan R.


Ok I think that because of the UITapGestureRecognizer .. try to do the following :

  1. connect an IBOutlet to your button.

2.assing the UITapGestureRecognizer delegate to your ViewController.

3.Implement this gesture delegate method in yourViewController

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 
       shouldReceiveTouch:(UITouch *)touch {
    return (! [yourButton pointInside:[touch locationInView:yourButton] withEvent:nil]);
}

This will make the tap to be recognized to your button not to the recognizer.

like image 28
Malek_Jundi Avatar answered Nov 10 '22 18:11

Malek_Jundi