gpt4 book ai didi

ios - UIPageViewController-PDF 缩放不工作 xcode?

转载 作者:行者123 更新时间:2023-11-28 22:22:55 25 4
gpt4 key购买 nike

我正在使用下面的github项目

https://github.com/jackhumphries/UIPageViewController-PDF

问题是 pdf 正在加载并且页面 curl 效果正在工作但是我无法放大和缩小我加载的 pdf 文档我也尝试调试然后为什么它不起作用但我找不到解决方案我检查了 PDFScrollView 委托(delegate)方法,它们都已实现,但当我尝试放大/缩小时,这些方法没有调用。

这里有这些方法:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{

return self.tiledPDFView;
}

- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
{
// Remove back tiled view.
[self.oldTiledPDFView removeFromSuperview];

// Set the current TiledPDFView to be the old view.
self.oldTiledPDFView = self.tiledPDFView;

[self addSubview:self.oldTiledPDFView];
}

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
// Set the new scale factor for the TiledPDFView.
_PDFScale *= scale;

// Calculate the new frame for the new TiledPDFView.
CGRect pageRect = CGPDFPageGetBoxRect(_PDFPage, kCGPDFMediaBox);

pageRect.size = CGSizeMake(pageRect.size.width*_PDFScale, pageRect.size.height*_PDFScale);

// Create a new TiledPDFView based on new frame and scaling.
TiledPDFView *tiledPDFView = [[TiledPDFView alloc] initWithFrame:pageRect scale:_PDFScale];

[tiledPDFView setPage:_PDFPage];

// Add the new TiledPDFView to the PDFScrollView.
[self addSubview:tiledPDFView];

self.tiledPDFView = tiledPDFView;
}

我有这段代码:

-(id)initWithPDFAtPath:(NSString *)path {

NSURL *pdfUrl = [NSURL fileURLWithPath:path];

PDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfUrl);

totalPages = (int)CGPDFDocumentGetNumberOfPages(PDFDocument);

self = [super initWithNibName:nil bundle:nil];

return self;

}

我想在上面的代码下面实现这段代码

/*
Open the PDF document, extract the first page, and pass the page to the PDF scroll view.
*/
NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"TestPage" withExtension:@"pdf"];
CGPDFDocumentRef PDFDocument = CGPDFDocumentCreateWithURL((__bridge CFURLRef)pdfURL);
CGPDFPageRef PDFPage = CGPDFDocumentGetPage(PDFDocument, 1);
[(PDFScrollView *)self.view setPDFPage:PDFPage];
CGPDFDocumentRelease(PDFDocument);

最佳答案

将此方法添加到 PDFScrollView:

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

self.minimumZoomScale = 1.0;
self.maximumZoomScale = 3.0;
}
return self;
}

并将最后两行添加到scrollViewDidEndZooming

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
....
self.minimumZoomScale = 1.0/scale;
self.maximumZoomScale = 3.0*scale;

}

请注意,只有当页面处于最低缩放级别时,更改页面才会起作用(就像在几个阅读器应用程序中发生的那样)。

关于ios - UIPageViewController-PDF 缩放不工作 xcode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19829327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com