Question

I'm having some trouble achieving the result I need.

Using the method visibleRect of UIScrollView, and using the gesture recognizer, I can get where, in the screen, the user touched, or draw a rect, for example.

Where I'm having some trouble is getting the information of where that touch event is relative to the document shown in the UIScrollView.

So, if I have a document like A4 size or Letter size, and the visible part is the bottom of that document, using the above method I can see the user tapped the top content of the window. But how can I know what that point refers to the document shown?

Was it helpful?

Solution

Use contentOffset to achieve that:

Add scroll offest to x and y touches:

CGFloat xOffset = _myScrollView.contentOffset.x;
CGFloat yOffset = _myScrollView.contentOffset.y;

Then take of it the position of the scrollview:

CGRect frame = _myScrollView.frame;

All:

CGFloat pdfTouchX = screenTouchX - frame.origin.x + xOffset;
CGFloat pdfTouchY = screenTouchY - frame.origin.y + yOffset;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top