12

I have the issue in two completely different situations, which makes it really weird.

  1. Situation: A UIButton in as a subView of another UIView.
  2. Situation: UIBarButtonItem's in a UIToolBar.

In both situations the buttons's are only highlighted after a slight delay, approximately .5 - 1 second. Definitely to long to highlight the view when tapping it normally. They both work perfectly on the simulator, but not on a real device (I have an iPhone 5s with iOS 7.0.4).

What I tried
Setting the zPosition to the highest value (MAXFLOAT) of these views, to ensure nothing is blocking the tap.
Explicitly enabling the highlighting.

Both obviously doesn't worked.

Edit: Still not solved.

Leandros
  • 16,805
  • 9
  • 69
  • 108
  • Aren´t you doing something like server calls on main thread when tapping those buttons? That could cause a delay in the highlight. You should make those calls in background if yes. – FabKremer Nov 22 '13 at 00:14
  • is highlight an image in png format ? – Kunal Balani Nov 22 '13 at 00:46
  • I guess you are doing some heavy work when tapping those buttons. Image rendering is working on main thread. You may check IBAction funtion for the buttons. – Joey Nov 22 '13 at 00:54
  • I do nothing in the actions of the buttons, except logging that it has been tapped. – Leandros Nov 22 '13 at 08:50

3 Answers3

8

This can happen if the buttons are placed close to the bottom edge of the display. There's a conflict with the system edge gesture to present Control Center (or App Switcher on iPhone X and iPad). It delays touches for your buttons until it's determined the user isn't performing a system gesture.

If you would like, you can tell the system to give precedence to your gestures over the system gestures.

override func preferredScreenEdgesDeferringSystemGestures() -> UIRectEdge {
    return .bottom
}

Do note however that this will require the user swipe twice to activate the system gesture.

Jordan H
  • 52,571
  • 37
  • 201
  • 351
  • or in Objective-C : `-(UIRectEdge)preferredScreenEdgesDeferringSystemGestures { return UIRectEdgeBottom; }` – Sébastien May 28 '18 at 09:28
1

Are the UIButtons inside a UIScrollView ? If they are, the delay is there so the scrollview can determine whether the touch is for scrolling or it should be passed on to the subview.

See also UIButton touch is delayed when in UIScrollView

Community
  • 1
  • 1
Niels
  • 1,026
  • 9
  • 17
1

I know it's been a long time, but I just faced a similar issue:

  • My UIButton is a subview of UINavigationController.view
  • There's no delay on the simulator
  • But there's a delay to show the highlight on the device

I just found out that it only happens if I run the app from Xcode. If I disconnect the device and open the app from it's icon everything works just fine.

I hope it helps.

gfpacheco
  • 2,831
  • 2
  • 33
  • 50