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.
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.
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.
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.
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
}
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")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With