【问题标题】:How to know if user finished selecting text inside PDFView如何知道用户是否完成在 PDFView 中选择文本
【发布时间】:2021-07-01 11:03:37
【问题描述】:

macCatalyst 不支持鼠标事件,就像 AppKit 没有移植(maccatalyst)macOS 应用程序一样。 我需要知道用户何时使用鼠标或触控板使用PDFKit 在 PDF 文件中选择了部分文本。 也许有人有解决方案或可以提出一个想法,如何实现 mouseUptouchedEnded 方法?

【问题讨论】:

    标签: ios swift macos pdfkit mac-catalyst


    【解决方案1】:

    实现您自己的 GestureRecocongiser:

    import UIKit.UIGestureRecognizerSubclass
    
    class TouchUpGestureRecogniser: UIGestureRecognizer {
        
        override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {
            state = UIGestureRecognizerState(rawValue: 3)!
        }
        
        override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent) {
            state = UIGestureRecognizerState(rawValue: 4)!
        }
        
    }
    

    然后在您的 VC 中,PDFView 所在的位置:

    let customGesture = TouchUpGestureRecogniser(target: self, action: #selector(touchUp(_:)))
    customGesture.delegate = self
    pdfView.addGestureRecognizer(customGesture)
    

    最后:

    extension ViewController: UIGestureRecognizerDelegate {
        func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
            return true
        }
    }
    

    注意:如果您在 PDFView 上有超过 1 个手势,请测试它们,如果有任何问题,请使用 UIGestureRecognizerDelegate 函数合并它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      相关资源
      最近更新 更多