在 UIScrollView 上显示 PDF

发布于 2024-12-12 03:30:19 字数 198 浏览 0 评论 0原文

我找到了一个示例代码,用于在水平滚动的 UIScrollView 上显示 PDF 文件。它工作正常,但问题是它仅显示 2 页 PDF。我尽我最大的努力去解决这个问题,但我无法解决。你能给我帮助吗?

I found an example code for showing PDF file on a UIScrollView with horizontal scrolling. It works fine, but problem is it shows only 2 pages of PDF. I tried in my best to figure out the issue, but I couldn't figure it. Can you please give me help?

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

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

发布评论

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

评论(1

初见终念 2024-12-19 03:30:19

我查看了您在这个问题中指出的示例项目,和您一样,我可以看到它只显示它要显示的任何 PDF 文件的两页。

示例代码的问题出现在 PDFViewController.m 文件中。对于这些行:

PDFScrollView *page = [self dequeueRecycledPage];
if (page == nil) {
    page = [[[PDFScrollView alloc] initWithPage:index + 1 frame:[self frameForPageAtIndex:index]] autorelease];
} 

我添加了

else {
    [page setPage: index inFrame:[self frameForPageAtIndex: index]];
}

这些新行到 PDFScrollView.h

- (void) setPage: (NSInteger) onPage inFrame:(CGRect)frame;

和 PDFScrollView.m

- (void) setPage: (NSInteger) onPage inFrame:(CGRect) frame
{
    if(pdfView)
    {
        [pdfView removeFromSuperview];
        [pdfView release];
    }
    self.frame = frame;
    self.index = onPage;
    pdfView = [[PDFViewTiled alloc] initWithPage:onPage frame:self.frame];
    [self addSubview:pdfView];
}

这不是一个完美的修复。您会发现绘图不正确,尤其是在备份页面时。我将把它留给你作为一个练习来处理,但希望这是一个好的开始。

我希望它能帮助你。

I looked at that sample project you pointed to in this question and like you, I can see it only displays two pages of whatever PDF file it's given to display.

The problem with the sample code comes in the PDFViewController.m file. For these lines:

PDFScrollView *page = [self dequeueRecycledPage];
if (page == nil) {
    page = [[[PDFScrollView alloc] initWithPage:index + 1 frame:[self frameForPageAtIndex:index]] autorelease];
} 

I added

else {
    [page setPage: index inFrame:[self frameForPageAtIndex: index]];
}

And also these new lines into PDFScrollView.h

- (void) setPage: (NSInteger) onPage inFrame:(CGRect)frame;

And PDFScrollView.m

- (void) setPage: (NSInteger) onPage inFrame:(CGRect) frame
{
    if(pdfView)
    {
        [pdfView removeFromSuperview];
        [pdfView release];
    }
    self.frame = frame;
    self.index = onPage;
    pdfView = [[PDFViewTiled alloc] initWithPage:onPage frame:self.frame];
    [self addSubview:pdfView];
}

This isn't a perfect fix. You'll see the drawing isn't proper, especially when backing up pages. I'll leave that to you as an exercise to take care of, but hopefully this is a nice start.

And I hope it helps you out.

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