For detecting touches in iOS application we use UITapGestureRecognizer. When we need react only on special number of touches, for example two or three, we must simply specify this parameter for gesture recognizer object.
When number of touches is 3
let tapGestureRecognizer = UITapGestureRecognizer(target: self,
action: #selector(imageTappedTriple))
tapGestureRecognizer.numberOfTapsRequired = 3
When number of touches is 2
let tapGestureRecognizer = UITapGestureRecognizer(target: self,
action: #selector(imageTappedDouble))
tapGestureRecognizer.numberOfTapsRequired = 2
Important to remember is make enable image for interaction with user.
self.imageView.isUserInteractionEnabled = true
Full code.
import UIKit
class ViewController: UIViewController {
@IBOutlet var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let tapGestureRecognizer = UITapGestureRecognizer(target: self,
action: #selector(imageTappedTriple))
tapGestureRecognizer.numberOfTapsRequired = 3
self.imageView.isUserInteractionEnabled = true
self.imageView.addGestureRecognizer(tapGestureRecognizer)
}
@objc func imageTappedTriple(sender: UITapGestureRecognizer) {
print("Image was tapped three times!")
}
}
You have shared a very informative Article. I was looking for this kind of unique information. Please share more related information so I can get more knowledge.
ReplyDelete-Custom Web Design and Development
There are many articles circulating on internet that exaggerate about Custom Designed Websites. But your article is an exception that made me understand it without any difficulty.
ReplyDeleteThis is an excellent article! Thank you a lot. I'm in desperate need of these suggestions. The in-depth explanation is quite beneficial. It was incredibly encouraging to see how you write. Best Custom Websites
ReplyDeleteThank you Sir, you made it easy as pie. Now i am able to understand and have enough knowledge about this. It is only because of you.
ReplyDeleteCustom Designed Websites
Amazing write-up! The blog was very informative. Keep it up!
ReplyDeleteSoftware Testing Services