开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜