自动调整 PDF 查看器的 UIView 大小

发布于 2024-10-10 06:29:16 字数 636 浏览 0 评论 0原文

我正在尝试自动调整大小以与我为 iPad 构建的 PDF 查看器一起使用。

我的视图结构包括:

Scroll view
    Document view
        Page view
        Page view
        Page view

如下图所示: https://i.sstatic.net/unV4J.png

我在显示 PDF 页面时没有遇到问题。出于这个问题的目的,我们假设每个页面都是一个 UIImageView。

为了创建视图,我一页一页地加载所有页面,并设置框架,使它们具有正确的尺寸,并且它们之间有 10 像素的间距。然后我将文档视图框架设置为所有页面的总大小。然后,我将文档视图添加到滚动视图。这很好用。

问题在于自动调整大小。我希望文档视图(以及其中的页面视图)的宽度随着滚动视图宽度的缩放而缩放。文档视图和页面显然需要保持其纵横比,因此宽度和高度需要灵活。但是,如果我使页面高度灵活,则页面框架高度将变为文档视图的高度。

我现在已经玩了几个小时试图让它正确布局,但我没有成功。之前我刚刚更新了旋转框架,但如果能够平滑调整大小,那就太好了。

I'm trying to get autoresizing to work with a PDF viewer I have built for iPad.

My view structure consists of:

Scroll view
    Document view
        Page view
        Page view
        Page view

As demonstrated in this diagram: https://i.sstatic.net/unV4J.png

I don't have a problem with displaying the PDF pages. Let's say for the purposes of this question that each page is a UIImageView.

To create the view I load all the pages one by one, and set the frames so they are the correct size and have a 10px spacing between them. Then I set the Document View frame to be the total size of all the pages. I then add the document view to the scroll view. This works fine.

The problem is with autoresizing. I want the width of the document view (and the page views inside it) to scale as the scroll view width scales. The document view and the pages obviously need to maintain their aspect ratio, so the width and height need to be flexible. However, if I make the page height flexible, the page frame height becomes that of the document view.

I've played around for hours now trying to get this to lay out properly, but I've had no success. Previously I have just updated the frames on rotation but it would be nice to get this working with the smooth resizing.

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

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

发布评论

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

评论(1

辞取 2024-10-17 06:29:16

我以编程方式解决了这个问题。

首先,我尝试使用layoutSubviews UIView 方法在调整大小时重新定位子视图。然而,这只在动画开始时发生一次(使用 MGSplitViewController,在其他情况下可能会有所不同),所以我重写了 setFrame 方法来重新定位那里的子视图。这非常有效,现在我的视图可以顺利地移动到它们应该在的位置。

如果其他人可以帮助我使用自动调整大小,那么我会认为这是一个更好的答案,但目前我对这个解决方案感到满意。

I solved this programmatically.

First I tried to use the layoutSubviews UIView method to reposition the subviews when resized. However this only occured once at the beginning of an animation (Using MGSplitViewController, it might be different in other situations), so instead I overrode the setFrame method to reposition the subviews there. This works great and now my views smoothly animate to where they should be.

If anyone else can help me with using autoresizing then I would consider that a better answer, but for the time being I'm happy with this solution.

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