I'm running into a small issue in my app.
I essentially have a series of UIButtons
added as subviews in a UIScrollView
which is part of a nib. Every time I tap on a button there is a noticeable delay before the button is highlighted. I essentially have to hold it for about half a second before the button dims and appears selected.
I'm assuming this is because the UIScrollView
needs to determine if the touch is a scroll or if it's a touch that is meant for a subview.
Anyways, I'm a little unsure on how to proceed. I simply want the button to appear selected as soon as I tap it.
Any help is appreciated!
Edit:
I've tried setting delaysContentTouches
to NO but scrolling becomes almost impossible since a majority of my scrollView is filled with UIButtons
.
Ok I've solved this by subclassing
UIScrollView
and overridingtouchesShouldCancelInContentView
Now my
UIButton
that was tagged as 99 highlights properly and my scrollview is scrolling!myCustomScrollView.h:
and myCustomScrollView.m:
Storyboard solution: Select the scroll view, open the "Attributes Inspector" and uncheck "Delays Content Touches"
Try to set UIScrollView
delaysContentTouches
property to NO.Swift 3 :
Jeff's solution wasn't quite working for me, but this similar one does: http://charlesharley.com/2013/programming/uibutton-in-uitableviewcell-has-no-highlight-state
In addition to overriding
touchesShouldCancelInContentView
in your scroll view subclass, you still need to setdelaysContentTouches
tofalse
. Lastly, you need to returntrue
rather thanfalse
for your buttons. Here's a modified example from the above link. As commenters suggested, it checks for any subclass ofUIControl
rather thanUIButton
specifically so that this behavior applies to any type of control.Objective-C:
Swift 4:
In Swift 3:
You can then use this
ScrollViewWithButtons
in IB or in code.