簡體   English   中英

如何刪除突出顯示的pdf注釋?

[英]How can you remove highlighted pdf annotations?

我在我的 pdf 視圖中設置了一個搜索欄,可以突出顯示我正在尋找的詞。 當我嘗試刪除突出顯示以便我可以搜索新詞時。 我試圖反轉我所做的,將顏色更改為白色,並刪除注釋,但沒有任何效果。我想在用戶單擊取消按鈕時清除突出顯示。 我究竟做錯了什么?

func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
    i = 0
    unhighlight(searchTerms: [searchWord])
    searchBar.text! = ""
}




private func highlight(searchTerms: [String]?)
{


    searchTerms?.forEach { term in
        selections = pdfView.document?.findString(term, withOptions: [.caseInsensitive])

        selections?.forEach { selection in
            selection.pages.forEach { page in
                highlight = PDFAnnotation(bounds: selection.bounds(for: page), forType: .highlight, withProperties: nil)
                highlight.endLineStyle = .square
                highlight.color = UIColor.orange.withAlphaComponent(0.5)

                page.addAnnotation(highlight)
            }
        }
    }
}


func unhighlight(searchTerms: [String]?)
{


    searchTerms?.forEach { term in
        selections = pdfView.document?.findString(term, withOptions: [.caseInsensitive])

        selections?.forEach { selection in
            selection.pages.forEach { page in
                highlight = PDFAnnotation(bounds: selection.bounds(for: page), forType: .highlight, withProperties: nil)
                highlight.endLineStyle = .square
                highlight.color = UIColor.white.withAlphaComponent(0.5)

                page.addAnnotation(highlight)



            }
        }
    }
}

不確定您是否曾經解決過您的問題,但是我相信您只需將這些注釋傳遞給內置於 PDFView 中的 self.highlightedselections 數組。 將該數組設置為 nil 應該清除突出顯示,而不是創建您自己的注釋。

在搜索中,它應該提供一個 PDFSelection,您可以在其中設置 .color 屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM