简体   繁体   English

swift UITapGestureRecognizer 转doubleTap换个视图

[英]swift UITapGestureRecognizer transfer doubleTap for another view

In my ViewController i have mapView - maps.在我的 ViewController 中,我有 mapView - 地图。 In map, if user double tap, map zoom in. It is default option, i did not set it up.在map中,如果用户双击,map放大。这是默认选项,我没有设置它。 I add UITapGestureRecognizer, because i work with single tap.我添加了 UITapGestureRecognizer,因为我使用的是单击。 But when i double tap, work twice single tap.但是当我双击时,单击两次。 I don't want write method for double tap, because mapView understand it.我不想为双击编写方法,因为 mapView 理解它。 I think that UITapGestureRecognizer must work with single tap, and don't work when double tap.我认为 UITapGestureRecognizer 必须在单击时工作,而在双击时不起作用。 My code:我的代码:

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

How i can我怎么能

you need to add the require(toFail:) method.您需要添加require(toFail:)方法。 like this uiTapGestureRecognizer1.require(toFail:uiTapGestureRecognizer2)像这样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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM