The issue occurs because PDFView doesn’t automatically refresh its rendering when annotations are removed or added dynamically. It treats annotation changes as part of the page content, so the UI may not update correctly for images or custom annotations.
I solved it by forcing PDFView to reload the affected page:
func pdfEditor(_ pdfEditor: PDFEditor, didUpdateAnnotationsOn page: PDFPage) {
guard let pdfView = self as? PDFView,
let document = pdfView.document else { return }
let pageIndex = document.index(for: page)
// Remove and re-insert the page to trigger a full redraw
document.removePage(at: pageIndex)
document.insert(page, at: pageIndex)
pdfView.setNeedsDisplay(pdfView.bounds)
}
This forces the PDFView to completely redraw the page, ensuring added or removed annotations appear correctly. It updates only the affected page, keeping it memory-efficient and smooth.
Topic:
Graphics & Games
SubTopic:
General
Tags: