Calculate position of NSScrollView relative to main image
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 coord开发者_Go百科inates of the view relative to the whole image)?
Thanks in advance :-)
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.
精彩评论