Natan R.
Natan R.

Reputation: 5181

IBAction UIButton firing is delayed

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

The Problem:

The Facts:

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

Upvotes: 10

Views: 5039

Answers (4)

Plato
Plato

Reputation: 651

In my case, there was a delay on IBAction for a button that was in a custom CalloutView of an MKAnnotationView.

In the same way there is a ~0.5sec delay between pressing the MKAnnotationView and the MKAnnotationView actually being selected, there is also a delay between any other user interactions you might add as a subview of the MKAnnotationView.

The solution is to disable the native UIGestureRecognizer within MapView that is causing the delay of any MKAnnotation view selections.

This can be done with the solution on this post:

Set isZoomEnabled = false within a gesture recognizer attached to the mapview on any tap, then set isZoomEnabled = false within a 0.5sec async dispatch.

Upvotes: 0

Natan R.
Natan R.

Reputation: 5181

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

Upvotes: 14

Malek_Jundi
Malek_Jundi

Reputation: 6160

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.

Upvotes: 8

Nathan C.
Nathan C.

Reputation: 319

Make sure your touch event is set the first contact of the button which would be the touch down event otherwise there will be a delay in the action until whichever other event you chose gets completed (i.e. touch up inside, touch up outside, etc).

Upvotes: 0

Related Questions