Ios pdf缩放特定坐标

时间:2013-12-26 04:03:50

标签: ios pdf zooming

我在Apple pdf缩放后创建了一个用于阅读pdf文档的IOS应用程序 https://developer.apple.com/library/ios/samplecode/zoomingpdfviewer/Introduction/Intro.html

但是,我不知道如何自动缩放特定坐标的pdf页面,

我的意思是当我的加载方法时,pdf页面在特定坐标(x,y)处缩放,例如:(10,20)

有些人帮我吗?请 !

谢谢!

1 个答案:

答案 0 :(得分:1)

From Apple's Sample Code of Zooming PDF Viewer

UIScrollView具有执行此操作的API

 [yourScrollView zoomToRect:CGRectMake(X, Y, Width, Height) animated:YES];

基本上,如果您想在更改中看到动画,那么您可以将代码放入View did Appear方法中。

#import "ZoomingPDFViewerViewController.h"
#import "PDFScrollView.h"
#import <QuartzCore/QuartzCore.h>

@implementation ZoomingPDFViewerViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    /*
     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);                
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    // 1. Get the Scroll View
    UIScrollView *scrollView =  (UIScrollView*)self.view;

    // 2. Zoom to specified rect
    [scrollView zoomToRect:CGRectMake(X, Y, Width, Height) animated:YES];


}