简体   繁体   English

如何删除突出显示的pdf注释?

[英]How can you remove highlighted pdf annotations?

I've set up a search bar in my pdf view and can highlight the words I'm looking for.我在我的 pdf 视图中设置了一个搜索栏,可以突出显示我正在寻找的词。 When I try to remove the highlights so that I can search for new words.当我尝试删除突出显示以便我可以搜索新词时。 I've tried to reverse what I did, change the color to white, and remove annotations yet nothing is working.I'm wanting to clear the highlights when the user click the cancel button.我试图反转我所做的,将颜色更改为白色,并删除注释,但没有任何效果。我想在用户单击取消按钮时清除突出显示。 What am I doing wrong?我究竟做错了什么?

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)



            }
        }
    }
}

Not sure if you ever solved your issue, however i believe you simply pass in those annotations to the self.highlightedselections array built into PDFView.不确定您是否曾经解决过您的问题,但是我相信您只需将这些注释传递给内置于 PDFView 中的 self.highlightedselections 数组。 Setting that array to nil should clear out the highlights, instead of creating your own annotations.将该数组设置为 nil 应该清除突出显示,而不是创建您自己的注释。

On the search, it should provide a PDFSelection, in which you set the .color attribute在搜索中,它应该提供一个 PDFSelection,您可以在其中设置 .color 属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM