问题描述
将注释添加到PDFPage(并在屏幕上呈现)后,无法在 PDFPage
/ PDFView上更新其外观
。
After adding annotation to PDFPage (and rendering it on a screen), there is no way to update its appearance on PDFPage
/PDFView
.
重现问题:
-
创建PDFAnnotation并将其添加到
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)
呈现后在PDFPage上,尝试编辑其边界/颜色/背景颜色/字符串值等:
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)
没有任何反应。
我知道一个技巧:
page.removeAnnotation(annotation)
page.addAnnotation(annotation)
但它是一种解决方法,而不是真正的解决方案。
but it is rather a workaround, not real solution.
推荐答案
你不能只使用'FreeText'类型的PDFAnnotation。更改边界时,将更新此注释类型的大小。我知道用户不能编辑这种类型的事实,但也许你不需要这个。
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.
这篇关于将PDFAnnotationSubtype等于.widget的PDFAnnotation在将其添加到PDFPage后不会刷新其外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!