【问题标题】:QLPreviewController and touchesBegan methodQLPreviewController 和 touchesBegan 方法
【发布时间】:2016-07-17 22:37:29
【问题描述】:

我正在使用 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)

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

【问题讨论】:

    标签: ios objective-c swift uipangesturerecognizer touchesbegan


    【解决方案1】:

    我还没有评论的声誉。

    要回答您的问题,您正确地继承了 QLPreviewController。但是,您的打印方法不起作用是一个完全不同的问题。让任何手势识别器与 QLPreviewController 一起工作非常困难。

    如果你得到它,请告诉我。

    【讨论】:

    • 我决定使用 UIWebView 并将我的 PDF 加载到他们的...它就像一个冠军
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多