1

If you just put a UIButton in a UIScrollView, the button does not highlight when you tap on it quickly. Instead, you have to tap and hold for a while before the button highlights. According to the documentation, this is because UIScrollView waits a little to determine if the user intends to drag the scroll view before forwarding touches to the views in the scroll view.

As noted in several Stackoverflow answers (such as this one: https://stackoverflow.com/a/19656611/2135004), the solution is to prevent this delay by setting the delaysContentTouches property of UIScrollView to NO. (An additional step is to subclass UIScrollView to override touchesShouldCancelInContentView: to return YES for UIButtons, so the user can still scroll the scroll view if the user initially touched the button in the scroll view.)

However, interacting with the App Store app seems to suggest another solution. (Although it may be a little picky, one reason I am not going with the solution where delaysContentTouches is set to NO is because I do not want the button to highlight if the user quickly drags on a button to scroll the scroll view. This is actually the highlighting behavior UITableViewCells.) Consider the following screenshot of the App Store app:

App Store Screenshot Showing Buttons

The blue "Quick Links" buttons (namely, "App Collections," "Game Collections," and "Apps Made by Apple") seem to be implemented as UIButtons with the UIButtonTypeSystem style because their highlighting fades in and out as you drag your finger in and out of them. In addition, the scroll view's delaysContentTouches property does not seem to be set to NO because the blue "Quick Links" buttons do not highlight when you quickly tap on them. However, the gray bordered buttons (namely, "Redeem," "Send Gift," and "Apple ID: ...") do highlight when you quickly tap on them! (Their highlighting also fades in and out as you drag your finger in and out of them.) Also note that the buttons do not highlight when you just happen to be touching them when you drag the scroll view.

How are these gray bordered buttons implemented? The key behavior I want is that they highlight when you quickly tap on them in a scroll view that delays content touches. (They should also highlight and unhighlight as you drag your finger in and out of them like plain UIButtons, preferably by fading their highlighting.) I do not see how this could be easily achieved by just subclassing UIButton, and I'm not even sure if somehow subclassing UIControl to create a new button class would work either.

Community
  • 1
  • 1
ememem
  • 968
  • 1
  • 10
  • 23

1 Answers1

0

I think what's happening here is that the grey button's highlighted state is being set when its action fires, then unset when the resulting alert or sheet is shown.

(If you're not showing an alert or a sheet, you'll just have to arrange for it to be unhighlighted on the next run loop.)

hatfinch
  • 3,095
  • 24
  • 35
  • I tried this out. Your solution is close. You actually have to set the highlighted state on the NEXT run loop after the action fires, not when the action fires. Then you can unhighlight it in the next run loop after that, as you've said. It even seems to not interfere with the fading out of the highlighting when you hold the button down for a bit before releasing it. Any ideas why it works for this edge case? – ememem Feb 14 '14 at 18:48
  • No ideas. Often these single-run-loop adjustments are really just catering to implementation details, so be sure to test early against future versions of iOS! – hatfinch Feb 17 '14 at 11:22