ios swift中pdfview的“菜单”中没有突出显示选项

Posted

技术标签:

【中文标题】ios swift中pdfview的“菜单”中没有突出显示选项【英文标题】:not getting highlight option in "menu" in pdfview in ios swift 【发布时间】:2018-08-20 11:00:14 【问题描述】:

我每次只得到这 3 个选项 当我的整个代码运行时,任何帮助将不胜感激。

let selections = pdfView.currentSelection?.selectionsByLine()
        guard (selections?.first?.pages.first) != nil else  return 
        selections?.forEach( selection in
            let newAnnotation = PDFAnnotation(bounds: selection.bounds(for: pdfView.currentPage!) ,forType: PDFAnnotationSubtype.highlight ,withProperties: nil)
            // Add additional properties to the annotation
            newAnnotation.color = #colorLiteral(red: 0.9254902005, green: 0.2352941185, blue: 0.1019607857, alpha: 1)
            self.pdfView.currentPage?.displaysAnnotations = true

            self.pdfView.currentPage?.addAnnotation(newAnnotation)
        )

【问题讨论】:

【参考方案1】:

我也在为这个问题苦苦挣扎,但在 ios 中找不到将其添加到 PDFView 的任何选项。 最后,我偶然发现了一种通过共享 UIMenuController 类添加菜单项的通用方法。

let menuItem    = UIMenuItem(title: "Highlight", action: #selector(HighLightHandler.highlightSelection(_:)))
UIMenuController.shared.menuItems = [menuItem]

并处理任何亮点:

@objc func highlightSelection(_ sender: UIMenuItem) 
        //put your highlighting code here

【讨论】:

以上是关于ios swift中pdfview的“菜单”中没有突出显示选项的主要内容,如果未能解决你的问题,请参考以下文章