为了自定义预览文件控制器,我创建了DocumentPreviewController: UIController
,然后创建了DocumentPreviewController.view.addSubView(QLPreviewController.view)
。如果我全屏显示QLPreviewController.view
,即使我为touch event
添加了UIGestureRecognizer
,也无法收到任何QLPreviewController.view
,并监控DocumentPreviewController
中的所有触摸事件}。任何人都可以帮助我吗?
import UIKit
import QuickLook
class CustomiseDocumentPreviewController: UIViewController, UIGestureRecognizerDelegate
{
var url : String!
override func viewDidLoad()
{
let previewController = CustomisePreviewController()
previewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, 300)
previewController.filePath = url
let singleGuesture = UITapGestureRecognizer()
singleGuesture.addTarget(self, action: #selector(GlipDocumentPreviewController._singleTap))
singleGuesture.numberOfTapsRequired = 1
singleGuesture.delegate = self
previewController.view.userInteractionEnabled = true
previewController.view.addGestureRecognizer(singleGuesture)
previewController.view.multipleTouchEnabled = true
self.view.backgroundColor = UIColor.redColor()
self.view.addSubview(previewController.view)
}
func _singleTap()
{
if self.navigationController!.navigationBarHidden
{
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
else
{
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
// self.navigationController?.navigationBarHidden = !(self.navigationController!.navigationBarHidden)
print("====")
}
public func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool
{
return true
}
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool
{
return true
}
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOfGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool
{
return true
}
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailByGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool
{
return true
}
public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool
{
return true
}
===========
import QuickLook
class CustomisePreviewController: QLPreviewController, QLPreviewControllerDataSource, QLPreviewControllerDelegate
{
var filePath : String?
override func viewDidLoad()
{
self.dataSource = self
self.listSubViewOfView(self.view)`
}
func numberOfPreviewItemsInPreviewController(controller: QLPreviewController) -> Int {
return 1
}
func previewController(controller: QLPreviewController, previewItemAtIndex index: Int) -> QLPreviewItem {
return NSURL(fileURLWithPath: filePath!)
}
func previewController(controller: QLPreviewController, shouldOpenURL url: NSURL, forPreviewItem item: QLPreviewItem) -> Bool {
return true
}
func previewControllerDidDismiss(controller: QLPreviewController)
{
}
func previewControllerWillDismiss(controller: QLPreviewController)
{
}
我已向CustomiseDocumentPreviewController.view
和CustomisePreviewController.view
添加单个触摸事件,您可以从我的代码中看到,屏幕上半部分为CustomisePreivewController.view
,如果我触摸该空间, 什么都没发生。但是,如果我触摸下面的屏幕,它可以工作。
我搜索了几天,似乎我们无法从QLPreviewController
获得触摸事件?
1.如果您有任何方法可以听取QLPreviewController.view'触摸事件,请帮帮我。
2.如果不能,如果需要自定义预览文件控制器,将如何操作。