0

I have a UIScrollView that contains several UIButtons. Each button is wired up to take an action when the user inputs a touch up event, so they are able to place their finger on the button and it will not be selected until it is raised. Currently, if I made a swipe gesture to scroll the UIScrollView quickly, then the scroll view moves as expected even if the gesture happens directly over a UIButton. HOWEVER, if I hold my finger down too long on a UIButton (about 1 second), the UIScrollView will no longer recognize the gesture and will not be able to scroll until the finger is lifted up.

I am wondering if their is a way to always have the UIScrollView recognize the scroll gesture? Note that this is not an issue if I touch the UiScrollView in a location without a UIButton - it then scrolls as expected.

lehn0058
  • 19,977
  • 15
  • 69
  • 109

2 Answers2

0

It may worth a try to let your UIButton respond to UIControlEventTouchDown (maybe with an empty action). I'm not sure if this will work, but conceptually I think it should let the UIButton capture the touch immediately.

(Also make sure you don't enable delaysContentTouches on your scrollview.)

danqing
  • 3,348
  • 2
  • 27
  • 43
  • Actually, I need it to respond to UIControlEventTouchUp. I don't want the button to respond immediately and I want the button event to be canceled if the touch input changes to a scroll event. – lehn0058 Jul 31 '12 at 00:44
  • No I mean, put an empty `IBAction` for `UIControlEventTouchDown` just to hijack the touch from being sent to the scrollview, and then implement whatever you want the button to do in `UIControlEventTouchUp`. – danqing Jul 31 '12 at 15:12
0

I found the answer to this here: UIScrollview with UIButtons - how to recreate springboard?

Essentially, I had to extend UIScrollView and override touchesShouldCancelInContentView, having it always return YES.

Community
  • 1
  • 1
lehn0058
  • 19,977
  • 15
  • 69
  • 109