1
votes

Imagine a UIButton and a user who taps somewhere OUTSIDE the button and then slides onto it. If I want the button to detect such touches I can register it for any "Touch Drag Enter" events.

My question: is there some way to achieve the same for a UIScrollView? I.e., I tap somewhere outside the scrollview, drag my finger onto the scrollview and as soon as I enter the scrollviews frame it starts panning? (Because by default it doesn't, I have to start my touch INSIDE the scrollview in order to pan)

2

2 Answers

1
votes

Imagine a UIButton and a user who taps somewhere OUTSIDE the button and then slides onto it. If I want the button to detect such touches I can register it for any "Touch Drag Enter" events

Actually, no you can't. A UIControl will not get any of the control events unless the touch started in the control.

And that's for the same reason that you are seeing a similar effect with the scroll view. This is the entire basis of touch delivery on iOS. A touch "belongs" to the view that was initially touched.

After all, the runtime cannot possibly know that you are going to drag into the scroll view...

2
votes

If you want to do this, you will have to do a custom implementation using -touchesBegan, -touchesMoved, and -touchesEnded

The documentation for the UIResponder class (which all ViewControllers inherit from) that allows you to do this is here.

Hopefully you can figure out what to do from here. :)

As an extra hint, you will also most likely need to use this function

bool contains = CGRectContainsPoint(CGRect rect, CGPoint point);