PDFAnnotation with PDFAnnotationSubtype equal to .widget is not refreshing its appearance after adding it to PDFPage

谁说胖子不能爱 提交于 2019-12-20 19:42:32

问题


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:

  1. 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)
    
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!