QLPreviewController 和 touchesBegan 方法

QLPreviewController and touchesBegan method

我正在 Swift 中使用 QLPreviewController。到目前为止,我能够通过将 PDF 添加到我的子视图来显示 PDF,而不是推送或呈现它。这允许我在文档底部有一个自定义工具栏,在顶部有一个自定义导航。

现在我需要能够为我的 QLPreviewController 视图使用 touchesBegan 方法。

我正在做一些研究,结果我需要创建一个 QLPreviewController 的子类并覆盖 viewDidAppear 并添加一个 UITapGestureRecognizer。

我的问题是,如何创建 QLPreviewController 的子类?

看起来像这样吗?

import UIKit
import QuickLook

class QLPreview: QLPreviewController  {

    override func viewDidLoad()
    {
        //Do UITapGestureRecognizer
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
    {
        //Touch QLPreviewController view
    }

    func detectPan(recognizer:UIPanGestureRecognizer)
    {

    }


}

这是我将 QLPreviewController 视图添加到子视图的方式

viewPDF = QLPreviewController()

        viewPDF.dataSource = self

        viewPDF.delegate = self

        viewPDF.view.frame = CGRectMake(0, 60, 375.0, 667.0)

        self.view.addSubview(viewPDF.view)

        viewPDF.view.userInteractionEnabled = true

        self.navigationController?.toolbarHidden = false
        self.navigationController?.navigationBarHidden = false;

这是我的委托方法

 func numberOfPreviewItemsInPreviewController(controller: QLPreviewController) -> Int {
        return 1
    }

    func previewController(controller: QLPreviewController, previewItemAtIndex index: Int) -> QLPreviewItem {

        PDFTitle.title = fileNameGroup

        let localUrl = String(format:"%@/%@", PDFFilePath, fileNameGroup)
        let url = NSURL.fileURLWithPath(localUrl)

        return url
    }

任何帮助将不胜感激

更新

这是我到目前为止得到的....我像这样重写了我的子类:

import UIKit
import QuickLook

class QLPreview: QLPreviewController, UIGestureRecognizerDelegate  {

    override func viewDidLoad()
    {
        super.viewDidLoad()

        self.view.frame = CGRectMake(0, 60, 375.0, 667.0)

        let panRecognizer = UIPanGestureRecognizer(target:self, action: #selector(QLPreview.detectPan))

        self.view.userInteractionEnabled = true

        self.view.addGestureRecognizer(panRecognizer)
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
    {
        print("touching")
    }

    func detectPan(recognizer:UIPanGestureRecognizer)
    {
        print("detect")
    }

}

并像这样添加:

let preview = QLPreview()

        preview.delegate = self
        preview.dataSource = self

        self.view.addSubview(preview.view)

但我的打印方法仍然没有出现。

我还没有评论的声誉。

为了回答您的问题,您正确地对 QLPreviewController 进行了子类化。但是,您的打印方法不起作用是一个完全不同的问题。很难让任何手势识别器与 QLPreviewController 一起工作。

如果你成功了,请告诉我。