2013-12-16 1 views
0

Я использую PSPDFKit для iOS.Автоматическое обнаружение изображений из PDF

В PSPDFViewController ведьма соответствует PSPDFViewControllerDelegate я перезаписать - (BOOL)pdfViewController didTapOnPageView: atPoint:(CGPoint)viewPoint, и мне нужно проверить, если любое изображение [pageView.textParser.images] с этой страницы просматривалось.

Как мне совместить координаты my point [viewPoint] с координатами изображения?

Вкратце, я хочу реализовать автоматическое обнаружение изображений в формате pdf.

ответ

1

UPDATE: Я нашел ответ в PSPDFKIT примерах

- (void)pdfViewController:(PSPDFViewController *)pdfController didLoadPageView:(PSPDFPageView *)pageView { 
    // Iterate over all images and add button overlays on top. 
    // Accessing the text parser will block the thread, so it'll be better to access the in a background thread and than use the result on the main thread (but then you'll have to check if the pageView still points at the same page which would add too much complexity for this simple example.) 
    for (PSPDFImageInfo *imageInfo in [pageView.document textParserForPage:pageView.page].images) { 
     // Create the view 
     PSCAutoResizeButton *resizeButton = [PSCAutoResizeButton new]; 
     resizeButton.targetPDFRect = [imageInfo boundingBox]; 
     resizeButton.imageInfo = imageInfo; 
     resizeButton.showsTouchWhenHighlighted = NO; 
     resizeButton.layer.borderColor = [UIColor redColor].CGColor; 
     resizeButton.layer.borderWidth = 0.f; 
     resizeButton.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.2f]; 
     [resizeButton addTarget:self action:@selector(imageButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
     // Add to container view. Only here views will get notified on changes via PSPDFAnnotationViewProtocol. 
     // The container view will be purged when the page is prepared for reusage. 
     [pageView.annotationContainerView addSubview:resizeButton]; 
    } } 

Private

- (void)imageButtonPressed:(PSCAutoResizeButton *)button { 
    NSParameterAssert([button isKindOfClass:PSCAutoResizeButton.class]); 

    PSPDFImageInfo *imageInfo = button.imageInfo; 
    UIImage *image = [imageInfo imageWithError:NULL]; 

    // Show view controller 
    if (image) { 
     UIViewController *imagePreviewController = [[UIViewController alloc] initWithNibName:nil bundle:nil]; 
     imagePreviewController.title = imageInfo.imageID; 
     UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
     imageView.contentMode = UIViewContentModeScaleAspectFit; 
     imageView.backgroundColor = UIColor.blackColor; 
     imagePreviewController.view = imageView; 
     [self presentModalOrInPopover:imagePreviewController embeddedInNavigationController:YES withCloseButton:YES animated:YES sender:button options:@{PSPDFPresentOptionAlwaysModal : @YES, PSPDFPresentOptionModalPresentationStyle : @(UIModalPresentationFormSheet)}]; 
    } } 

 Смежные вопросы

  • Нет связанных вопросов^_^