2016-10-17 47 views
2

PDFAnnotationText未在macOS sierra 10.12.1 Beta(16B2548a)上顯示彈出窗口。 012.已於10.12棄用,但新API不繪製註釋。PDFAnnotationText未在10.12上顯示彈出窗口

舊的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)。任何人都可以請幫我嗎?

回答

0

我能夠創建一個簡單的黑線標註像這樣(在斯威夫特3):

let document = pdfView!.document 
let page = document!.page(at:0) 
let pageBounds = page!.bounds(for: PDFDisplayBox.artBox) 
let annotation = PDFAnnotation() 
annotation.setValue("/FreeText", forAnnotationKey: kPDFAnnotationKey_Subtype) 
annotation.setValue("HELLO WORLD", forAnnotationKey: kPDFAnnotationKey_Contents) 
annotation.setValue(NSColor.clear, forAnnotationKey: kPDFAnnotationKey_Color) 
annotation.bounds = NSRect(x:10, y:pageBounds.height-50, width:400, height:40) 
page!.addAnnotation(annotation) 

它使用/ FreeText的,但也許它會幫助你,如果你用的值進行試驗。仍然無法弄清楚如何改變文字的顏色。