views:

626

answers:

4

I have a Class called Boards and it is a subclass of UIView, I allocated an instance of that and put it into a UIScrollView, I want to instead of he touches going to the UIScrollView, but to the subview: Boards(UIView), I just don't know how to pass the touches from the UIScrollView to the UIView.

P.S: I will be changing the contentOffset of the UIScrollView manually, so therefore I don't need the touches in the UIScrollView, but in the UIView.

P.S: The UIView Is receiving the touchesEnded, and touchesBegan event, just not touchesMoved

A: 

Try turning off delaysContentTouches in the scrollview. This will forward all child touches directly to the child views immediately, without checking to see if it's a 'scroll touch'.

Ben Gottlieb
This is not a solution just telling it to wait. NOT WORKING!
Jaba
A: 

Why don't you create a subclass of the UIScrollView? Then, pass the all touch events which are received by the subclass to the UIView like as follows.

@implementation SubclassOfScrollView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.nextResponder touchesBegan:touches withEvent:event];
}

@end
tomute
+1  A: 

If you want UIScrollView to only scroll programmatically, you must subclass it and override the touchesBegan/Moved/Canceled/Ended methods. Even then, you might have problems. UIScrollView was not designed to ignore user input.

If possible, you should replace UIScrollView with a custom view. Instead of changing the contentOffset, you could change the view's transform property to move around its content.

Or you could nest two views, and outer view and an inner view. Place your Boards view inside the inner view. Then, instead of changing contentOffset, change the inner view's frame.

If animation is important, I'm pretty sure the second option will provide an animated transition and the first one might too.

benzado
A: 

New updates on the issue here (including a link to ZoomScrollView source code + some excellent explanation on UIScrollView internals) .
Also, check out Apple's updated ScrollViewSuite example. It has your described scenario in the 3rd example.

DenTheMan