user18624814
user18624814

Reputation:

swift UITapGestureRecognizer transfer doubleTap for another view

In my ViewController i have mapView - maps. In map, if user double tap, map zoom in. It is default option, i did not set it up. I add UITapGestureRecognizer, because i work with single tap. But when i double tap, work twice single tap. I don't want write method for double tap, because mapView understand it. I think that UITapGestureRecognizer must work with single tap, and don't work when double tap. My code:

let tapTap = UITapGestureRecognizer(target: self, action: #selector(getObjectProperties))
tapTap.numberOfTapsRequired = 1
tapTap.delegate = self
mapView.addGestureRecognizer(tapTap)

How i can

Upvotes: 0

Views: 27

Answers (1)

Fault
Fault

Reputation: 1294

you need to add the require(toFail:) method. like this uiTapGestureRecognizer1.require(toFail:uiTapGestureRecognizer2)

here is the command in context

//DOUBLE TAP
uiTapGestureRecognizer2 = UITapGestureRecognizer(target:self, action:#selector(myDoubleTapGesture(_:)) )
uiTapGestureRecognizer2.numberOfTapsRequired = 2
uiTapGestureRecognizer2.delegate = self
view.addGestureRecognizer(uiTapGestureRecognizer2)

//SINGLE TAP
uiTapGestureRecognizer1 = UITapGestureRecognizer(target:self, action:#selector(mySingleTapGesture(_:)) )
uiTapGestureRecognizer1.numberOfTapsRequired = 1
uiTapGestureRecognizer1.delegate = self
view.addGestureRecognizer(uiTapGestureRecognizer1)

//so the *first* tap of a double doesn't trigger a single
uiTapGestureRecognizer1.require(toFail:uiTapGestureRecognizer2) //<-- this is the line you need

Upvotes: 0

Related Questions