0

以下の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);
4

1 に答える 1

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

最後の2行を追加しますscrollViewDidEndZooming

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

}

ページの変更は、ページが最小のズーム レベルにある場合にのみ機能することに注意してください (いくつかのリーダー アプリで発生するように)。

于 2013-11-07T08:46:56.600 に答える