UIPageViewController-PDF缩放不工作的xcode?

时间:2013-11-07 06:25:05

标签: ios objective-c uiview uiscrollview zoom

我使用下面的github项目

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

问题是pdf正在加载并且页面卷曲效果正在起作用但我无法放大并缩小我加载的pdf文档我尝试调试以及为什么它不能正常但我无法找到解决方案而且我签出了他们都实现的PDFScrollView委托方法,但是当我尝试放大/缩小时,这些方法没有调用。

以下是这些方法:

- (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);

1 个答案:

答案 0 :(得分:2)

将此方法添加到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;

}

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