0

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?

bneely
  • 9,083
  • 4
  • 38
  • 46
Rui Lopes
  • 2,562
  • 6
  • 34
  • 49

1 Answers1

1

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;
hasan
  • 23,815
  • 10
  • 63
  • 101