将PDFAnnotationSubtype等于.widget的PDFAnnotation在将其添加到PDFPage后不会刷新其外观

问题描述 投票:9回答:1

将注释添加到PDFPage(并在屏幕上呈现)后,无法在PDFPage / PDFView上更新其外观。

重现问题:

  1. 创建PDFAnnotation并将其添加到PDFPagelet 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. 在PDFPage上显示后,尝试编辑其边界/颜色/背景颜色/字符串值等: 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)

但这是一种解决方法,而不是真正的解决方案。

ios swift ios11 pdfkit
1个回答
0
投票

你不能只使用'FreeText'类型的PDFAnnotation。更改边界时,将更新此注释类型的大小。我知道这种类型不是用户可编辑的,但也许你不需要这样。

© www.soinside.com 2019 - 2024. All rights reserved.