views:

532

answers:

1

Hi all,

Just toying with the SDK and I was wondering if possible a UITouch event can work inside a UIScrollView.

I have setup a UIScrollView which handles a large UIView, inside the UIView is a UIImageView, I've managed to get the UITouch to drag the UIImageView outside of the UIScrollView but inside it's not registering the event.

I suppose what I was trying to accomplish was dragging the UIImageView around the large UIView whilst the UIScrollView moves along the image if the user drags it beyond the POS of when the UIView when the UIImageView began it's dragging, if that makes sense?

Many thanks

+1  A: 

(If I understood the question correctly)

UIScrollView intercepts touchMoved events and does not propagate them to its contents if scrolling is enabled. So to do the dragging in the UIScrollView contents in my app I did the following trick:

touchesBegan: Check if you touch the "draggable" region. If YES - disable scrolling in UIScrollView.

touchesMoved: Now as scrolling is disabled your contents view receives this event and you can move your draggable UIImageView accordingly.

touchesEnded: Reenable scrolling in UIScrolliew.

If you want to drag the view outside of the visible UIScrollView area you may also need to check manually if you're near the boundaries and manually adjust contents offset (I didn't try this myself but I think it should work).

Vladimir
Hey there, thanks for the response. I did something similar a couple of days ago. My original design had a single view controller managing the UIScrollView and the sub views within. I couldn't get the touchesBegin to register in the sub view until I used a separate view controller. Out of curiosity did you use a single view controller or multiple? And yes I believe I'd have to do a manual check, especially considering the way the user scrolls from say left to right will be different to dragging and object to the left.
Chris
I used single view controller and custom UIView subclass that handled touches.
Vladimir