我的 PDF ScrollView (从 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 的运行良好,没有错误,但如果我在我的应用程序中使用这一行,则在加载该 View 时会出现以下错误:
-[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
我的设置中唯一的其他区别是调用它的 View Controller 位于导航 Controller 内,导航 Controller 位于选项卡栏 Controller 内。但我看不出这会对问题产生什么影响。
有什么建议吗?
[更新]
这是我的自定义初始化方法:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.decelerationRate = UIScrollViewDecelerationRateFast;
self.delegate = self;
self.scrollEnabled = true;
}
return self;
}
除了我添加了self.scrollEnabled = true;
之外,它与initWithCoder
相同。
我也试过这些,还是不行:
//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,但仍然没有缩放。
最佳答案
self.view
必须是 ScrollView 才能被转换为 PDFScrollView
并接受其方法。默认情况下,self.view
是一个 UIView。在 XIB 文件中将 View 更改为 ScrollView (删除 View 并将 ScrollView 链接到文件所有者中的 view
)或以编程方式执行。
关于iphone - PDF ScrollView 不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14306503/