Question

Assume I load an NSImage of dimensions 2000x2000 and display only a portion of the picture inside an NSScrollView with frame size 500x300. How can I calculate the distance between the images 0,0 origin and the views 0,0 origin (so I can determine the x,y coordinates of the view relative to the whole image)?

Thanks in advance :-)

Was it helpful?

Solution

Use the documentVisibleRect method:

NSRect rect=[scrollView documentVisibleRect];
CGFloat x=rect.origin.x;
CGFloat y=rect.origin.y;

x and y will be the coordinate on the image that's currently at the top left corner.

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