UIPageViewController-PDF Zooming not working xcode

2019-08-21 10:23发布

I'm using the the below github project

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

the problem is pdf is loading and page curl effect is working but i can not zoom in and zoom out my pdf document that is loaded i try debuging as well then why its not working but i can not find out the solution and i checked out the PDFScrollView delegate methods they all are implemented but those methods are not calling when i try to zoom in/out .

here are these methods :

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

And i have this code :

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

}

and i want to implement this code below to above code

/*
 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条回答
Emotional °昔
2楼-- · 2019-08-21 11:08

Add this method to 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;
}

and add the last two lines to scrollViewDidEndZooming

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

}

Notice that changing page will only work when the page is at its lowest zoom level (as in happens in several reader apps).

查看更多
登录 后发表回答