【问题标题】:how to add GestureRecognizer for PDFAnnotation ios swift 4如何为 PDFAnnotation ios swift 4 添加 GestureRecognizer
【发布时间】:2018-02-12 09:42:17
【问题描述】:

可以为 PDFAnnotation 添加 GestureRecognizer 或设置触摸

  func setDocumentAnnotation() {
    let anotation:PDFAnnotation = PDFAnnotation(bounds: CGRect(x: pointX, y: pointY, width: pointW, height: pointH), forType: .highlight, withProperties: nil)
        anotation.color = .yellow
        anotation.endLineStyle = .circle
        guard let page = pdfView.currentPage else {return}
        page.addAnnotation(anotation)
}


 @objc func annotationTapping(_ sender: UITapGestureRecognizer){
    print("------- annotationTapping ------")
}

【问题讨论】:

    标签: swift4 ios11 pdfkit pdf-annotations


    【解决方案1】:

    希望这种方法对你有用..

     NotificationCenter.default.addObserver(self, selector: #selector (titleTapped), name:Notification.Name.PDFViewAnnotationHit , object: nil)
    
      @objc func titleTapped()  {
           -Provide the action you want---
        }
    

    【讨论】:

      【解决方案2】:

      无法将手势识别器添加到注释本身。但是,您可以将其添加到PDFView,然后检查用户是否点击了注释。这是一个简单的sn-p:

      let tappedPage = pdfView.page(for: tapLocation, nearest: false)
      if let page = tappedPage {
          let tapPageLocation = pdfView.convert(tapLocation, to: page)
          let annotation = page.annotation(at: tapPageLocation)
      }
      

      我希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-02-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-05
        • 1970-01-01
        相关资源
        最近更新 更多