Reputation:
I've looked at previous answers to this question, but the solutions don't seem to work in my case (e.g. adding a requirement for the gesture recognizer to fail).
I have hooked up my view to a tap gesture recognizer, and I'm trying to use the following handler in my code:
@IBAction func doubleTapView(gesture: UITapGestureRecognizer) {
gesture.numberOfTapsRequired = 2
if gesture.state == .Ended {
print("Works")
}
}
This is what happens:
The first tap will print "Works". From then on, it will require the double-tap to print "Works"
How do I eliminate it printing on the first tap before it defaults to the correct and intended behaviour?
Upvotes: 0
Views: 142
Reputation: 1980
You need to set the number of touches before the @IBAction
function call.
There are two ways here:
Either in storyboard
Or create an IBOutlet and set it in the viewDidLoad()
function.
@IBOutlet weak var tapGesture: UITapGestureRecognizer!
override func viewDidLoad() {
super.viewDidLoad()
tapGesture.numberOfTapsRequired = 2
}
Upvotes: 1