PDF ScrollView不滚动

时间:2013-01-13 18:08:31

标签: iphone ios pdf uiscrollview

我的PDF滚动视图(从Apple’s ZoomingPDFViewer示例中复制,但稍微修改了一下)似乎无法缩放,尽管它​​正在显示数据。

以下是Apple在示例中用来添加它的内容:

CGPDFPageRef PDFPage = CGPDFDocumentGetPage(PDFDocument, 1);
[(PDFScrollView *)self.view setPDFPage:PDFPage];

因为第二行给了我错误,我改为:

CGPDFPageRef PDFPage = CGPDFDocumentGetPage(PDFDocument, 1);
PDFScrollView *sv = [[PDFScrollView alloc] initWithFrame:self.view.frame];
[sv setPDFPage:PDFPage];
self.view = sv;

但现在我似乎无法缩放PDF。

Apple one运行良好且没有错误,但如果我在我的应用程序中使用此行,则在该视图加载时出现以下错误:

-[UIView setPDFPage:]: unrecognized selector sent to instance 0x1c5b10b0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setPDFPage:]: unrecognized selector sent to instance 0x1c5b10b0'
*** First throw call stack:
(0x3424c2a3 0x33a1e97f 0x3424fe07 0x3424e531 0x341a5f68 0x8c499 0x36da3595 0x36df813b 0x36df8081 0x36df7f65 0x36df7e89 0x36df75c9 0x36df74b1 0x36de5b93 0x36de5833 0x79acd 0x36e46275 0x36ec8ea9 0x39249a6f 0x342215df 0x34221291 0x3421ff01 0x34192ebd 0x34192d49 0x34efb2eb 0x36dd8301 0x6e601 0x38e17b20)
libc++abi.dylib: terminate called throwing an exception

我的设置中唯一的另一个区别是调用它的视图控制器位于导航控制器内,导航控制器位于标签栏控制器内。但我看不出这会如何影响这个问题。

任何提示?

[UPDATE]

这是我的自定义init方法:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.decelerationRate = UIScrollViewDecelerationRateFast;
        self.delegate = self;
        self.scrollEnabled = true;
    }
    return self;
}

initWithCoder相同,只是我添加了self.scrollEnabled = true;

我也试过这些,但它仍然没有用:

//UIScrollView *sv = [[UIScrollView alloc] initWithFrame:self.view.frame];
PDFScrollView *sv = [[PDFScrollView alloc] initWithFrame:self.view.frame];
self.view = sv;
[(PDFScrollView *)self.view setPDFPage:PDFPage];

当我使用注释掉的行(UIScrollView)时,除了显示[UIScrollView setPDFPage:]: unrecognized...之外,它给出了同样的错误。当我使用未注释的行(PDFScrollView)时,它没有给我任何错误并显示PDF,但仍然没有缩放。

1 个答案:

答案 0 :(得分:2)

self.view必须是滚动视图才能转换为PDFScrollView并接受其方法。默认情况下,self.view是UIView。将视图更改为XIB文件中的滚动视图(删除视图并将滚动视图链接到文件所有者中的view)或以编程方式执行。

相关问题