【发布时间】:2013-01-13 18:08:31
【问题描述】:
我的 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 运行良好且没有错误,但如果我在我的应用程序中使用这一行,则在加载该视图时会收到以下错误:
-[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
我的设置中唯一的其他区别是调用它的视图控制器位于导航控制器内部,导航控制器位于选项卡栏控制器内部。但我看不出这会如何影响问题。
有什么建议吗?
[更新]
这是我的自定义初始化方法:
- (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,但仍然没有缩放。
【问题讨论】:
-
几周前我遇到了完全相同的问题。我现在不在电脑旁,但请尝试以下操作。在您的 XIB 文件中,您的视图控制器的视图必须是 UIScrollView,而不是 UIView。一旦你改变了这个并将滚动视图链接到 self.view,Apple 的代码应该可以工作了。
-
@JackHumphries 感谢您的提示,但我没有与任何 XIB 合作。
-
@JackHumphries 啊!那就是问题所在!非常感谢!哈哈
-
没问题!我要写这个作为答案,你能接受吗?谢谢。
-
@JackHumphries 是的!说出你的解决方案,以及检查 XIB 的连接。
标签: iphone ios pdf uiscrollview