计算 NSScrollView 相对于主图像的位置

发布于 2024-08-22 04:28:17 字数 150 浏览 5 评论 0原文

假设我加载尺寸为 2000x2000 的 NSImage 并仅在帧大小为 500x300 的 NSScrollView 内显示图片的一部分。如何计算图像 0,0 原点和视图 0,0 原点之间的距离(这样我就可以确定视图相对于整个图像的 x,y 坐标)?

提前致谢 :-)

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 :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独孤求败 2024-08-29 04:28:17

使用 documentVisibleRect 方法:

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

x 和 y 将是当前位于左上角的图像上的坐标。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文