Search code examples
iosuiscrollviewtouches

UIScrollview touches


I have an instance of UIScrollView which I'm allowing the user to zoom in/out. I've implemented a delegate to take care of this as per the docs. However, I'd like to know where the user is touching the scrollview (relative to the scrollview's superview's frame). Can I intercept this information, such as via some property of scrollviews, without overriding say touchesMoved:withEvent:?

[UIScrollView instances internally make a decision on the type of touch they received. I don't want to emulate this, I'd like to know the decision and the location of the touch.]


Solution

  • There is no property in scroll view which will tell you the location of the touch. You can know if it's being dragged or scrolled but you won't have the location of the touch. If you are hesitant about subclassing UIScrollView, you can look at a custom UIGestureRecognizer which will help you keep track of the current location. Once you have the UITouch object, you can get the location of the tap relative to superview using the locationInView: method.