Search code examples
iphoneuiviewuiscrollviewtouchesmoved

Why is my subclassed UIView not recieving touches moved when in a UIScrollView?


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


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.