【问题标题】:UIPageViewController-PDF Zooming not working xcode?UIPageViewController-PDF 缩放不工作 xcode?
【发布时间】:2013-11-18 16:59:36
【问题描述】:

我正在使用下面的 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);

【问题讨论】:

    标签: ios objective-c uiview uiscrollview zooming


    【解决方案1】:

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

    请注意,只有在页面处于最低缩放级别时才能更改页面(就像在几个阅读器应用中发生的情况一样)。

    【讨论】:

    • 非常感谢你是一个天才(Y) 非常感谢:) 它有效
    • 当我在最大上放大我的 pdf 时,然后当我尝试缩小实际大小时,它不会缩小实际大小,有时会卡在放大级别并缩小然后无法正常工作可以请告诉我我应该改变什么???
    • 你添加了我在scrollViewDidEndZooming 中提到的最后两行吗?或者,您可以查看我的框架分支:github.com/sdesimone/UIPageViewController-PDF
    • 是的,我在 scrollViewDidEndZooming 中添加了最后两行。我还检查了你上面提到的项目,你也可以在那里看到,缩小不能正常工作,放大工作正常但是当我尝试缩小时缩小有问题它无法完美响应它没有'没有进入它的实际位置,缩小有问题请指导我塞尔吉奥我在哪里做错了谢谢。
    • 我拉出了最新版本,但是当我放大到最大然后它不会缩小时,缩小不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多