以缩放不变的方式在 UIScrollView 中绘制图像

发布于 2025-01-04 05:56:46 字数 164 浏览 2 评论 0原文

我有一个 UIScrollView,它显示一个 UIView,它本身包含一个小的视图层次结构。这些子视图之一用于绘制图标(它们的逻辑含义是 PDF 页面上的便签标记)。目前,图标与所有其他内容一起缩放。但是,我想以相同的尺寸绘制它们,而不管当前的缩放比例如何(当然,它们的正确位置仍然必须保持)。最好的方法是什么?

I have a UIScrollView which displays a UIView which itself contains a small hierarchy of views. One of those sub-views is used to draw icons (their logical meaning are sticky note markers on a PDF page). Currently, the icons are zoomed along with all the other content. However, I want to draw them with the same size regardless of the current zoom (their correct position must still be maintained, of course). What's the best way to do this?

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

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

发布评论

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

评论(1

浸婚纱 2025-01-11 05:56:46

您基本上必须单独设置子视图的变换比例以匹配滚动视图的缩放系数。因此,每当您滚动时,循环遍历子视图,如果滚动视图缩放系数为 5.0,您将像这样设置变换:

CGFloat scaleFactor = 1.0/5.0; // 1.0 divided by the scrollview zoom factor
subview.transform = CGAffineTransformMakeScale(scaleFactor, scaleFactor);

从好的方面来说,它将正确居中,因此您所要做的就是设置变换和其他一切都应该正常工作(您不必操纵框架)。

You basically have to set the transform scale of the subviews individually to match the zoom factor of the scrollView. So whenever you scroll, loop through the subviews and if the scrollview zoom factor is, say, 5.0, you'd set the transform like this:

CGFloat scaleFactor = 1.0/5.0; // 1.0 divided by the scrollview zoom factor
subview.transform = CGAffineTransformMakeScale(scaleFactor, scaleFactor);

On the plus side, it will be centered correctly, so all you have to do is set the transform and everything else should just work (you don't have to manipulate the frame).

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