Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top