2

PDFAnnotationTextmacOS sierra 10.12.1 Beta (16B2548a) でポップアップが表示されません。PDFAnnotationTextは 10.12 で廃止されましたが、新しい API は注釈を描画していません。

古い API:

// display the PDF document
    [m_pdfView setDocument: [self pdfDocument]];

- (PDFDocument *)pdfDocument {
    // create a page

    PDFDocument *document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:@"/Users/test/Downloads/Eticket.pdf"]];
    PDFAnnotationText* result = [[PDFAnnotationText alloc] initWithBounds:NSMakeRect(100, 100, 40, 40)];
    result.color = [NSColor redColor];
    result.contents = @"Hello";
    result.iconType = kPDFTextAnnotationIconNote;
    // add it to the PDF document
    [[document pageAtIndex:0] addAnnotation:result];
    return document;
}

10.12 新しい API:

- (PDFDocument *)pdfDocument {
    // create a page
    PDFDocument *document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:@"/Users/test/Downloads/Eticket.pdf"]];

    NSMutableDictionary *popupDictionary = [[NSMutableDictionary alloc] init];

    [popupDictionary setObject:@"/Popup" forKey:kPDFAnnotationKey_Subtype];
    [popupDictionary setObject:[NSColor redColor] forKey:kPDFAnnotationKey_Color];
    [popupDictionary setObject:@"Hello" forKey:kPDFAnnotationKey_Contents];

    NSValue *rectValue = [NSValue valueWithRect:NSMakeRect(100, 100, 40, 40)];
    [popupDictionary setObject:rectValue forKey:kPDFAnnotationKey_Rect];

    PDFAnnotation *textAnnotation = [[PDFAnnotation alloc] initWithDictionary: popupDictionary forPage: [document pageAtIndex:0]];
    [[document pageAtIndex:0] addAnnotation:textAnnotation];    // add it to the PDF document
    return document;
}

Xcode バージョン 8.0 (8A218a) を使用しています。誰でも私を助けてもらえますか?

4

1 に答える 1