Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a tap gesture recognizer to PDFView in iOS 13

My code works in iOS 12. But after upgrading to iOS 13, it does not work.

let pinPointRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.pinPoint(sender:)))
pinPointRecognizer.numberOfTapsRequired = 1
self.pdfView.addGestureRecognizer(pinPointRecognizer)

I have tried adding the pinPointRecognizer.numberOfTouchesRequired = 2 and it can trigger pinPoint() function. But I want to trigger pinPoint() in a single tap.

Is this behaviour a bug that will be fixed in the future iOS version? Is there a workaround to fix this?

Thanks!

Updated:

Thank you all for your reply! I am sorry that I may not have the time to test all your answers. I have changed my app's behaviour to work around the problem.

I need to pin a point on PDF file. My workaround is to add an additional layer, which display a pin icon on the center of the PDFView. When a user tap on the PDF view, I will add one pin icon image annotation on the PDFView.

In a word, in my workaround, I still use the tap gesture recognizer. But the recognizer only pin a point on the center of current PDFView. User can zoom in/out and drag around to control where to pin the point.

like image 923
ysong4 Avatar asked Sep 30 '19 06:09

ysong4


People also ask

How do I add tap gestures?

Adding a Tap Gesture Recognizer in Interface Builder You don't need to switch between the code editor and Interface Builder. Open Main. storyboard and drag a tap gesture recognizer from the Object Library and drop it onto the view we added earlier. The tap gesture recognizer appears in the Document Outline on the left.

What is gesture tap?

Tap and swipe are two common gestures that allow the user to perform primary actions on their mobile devices. The tap gesture is essentially a brief touch of the mobile screen surface with the fingertip. Common uses of this gesture in iOS and Android devices include: Select or submit. Activate.

How do I use UITapGestureRecognizer?

The iOS UITapGestureRecognizer class has a built-in way to detect a double tap on any view. All you need to do is create the recognizer, set its numberOfTapsRequired property to 2, then add it to the view you want to monitor.


Video Answer


2 Answers

let singleTapGesture = UITapGestureRecognizer(target: self, action: #selector(toggleTopBottomView(_:)))
singleTapGesture.numberOfTapsRequired = 1
singleTapGesture.delegate = self
self.pdfContainerView.addGestureRecognizer(singleTapGesture)

@objc func toggleTopBottomView(_ sender: UITapGestureRecognizer){

}


func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true
}
like image 200
Mohamed Shah Avatar answered Dec 01 '22 09:12

Mohamed Shah


You can try this with Xcode 11, iOS 13

override func viewDidLoad() {
    super.viewDidLoad()

    let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))

    tap.numberOfTapsRequired = 1

    view.addGestureRecognizer(tap)

    view.isUserInteractionEnabled = true

}

@objc func handleTap(_ sender: UITapGestureRecognizer) {
    print("Tapped")
}
like image 45
Nick Avatar answered Dec 01 '22 11:12

Nick