问题
After adding annotation to PDFPage (and rendering it on a screen), there is no way to update its appearance on PDFPage
/PDFView
.
To reproduce the problem:
Create PDFAnnotation and add it to the
PDFPage
:let bounds = CGRect(x: 20.0, y: 20.0, width: 200.0, height: 200.0) let annotation = PDFAnnotation(bounds: b, forType: .widget, withProperties: nil) annotation.widgetFieldType = .text annotation.backgroundColor = .gray annotation.font = .systemFont(ofSize: 18) annotation.widgetStringValue = "Test!" page.addAnnotation(annotation)
After it is presented on a PDFPage, try to edit its bounds/color/background color/string value etc.:
annotation?.setValue("Help! SOS! Mayday!", forAnnotationKey: .widgetValue) annotation?.color = .green annotation?.bounds = CGRect(x: 0.0, y: 0.0, width: 100.0, height: 100.0)
Nothing happens.
I am aware of a trick:
page.removeAnnotation(annotation)
page.addAnnotation(annotation)
but it is rather a workaround, not real solution.
回答1:
Can't you just use PDFAnnotation of type 'FreeText'. The size of this annotation type is updated when it's bounds are changed. I'm aware of the fact that this type is not editable by the user, but maybe you don't need this.
来源:https://stackoverflow.com/questions/46815383/pdfannotation-with-pdfannotationsubtype-equal-to-widget-is-not-refreshing-its-a