gpt4 book ai didi

ios - 在 UIGestureRecognizer 中双击

转载 作者:搜寻专家 更新时间:2023-11-01 06:04:11 26 4
gpt4 key购买 nike

我的项目有一个自定义的 uitableviewCell,里面有一个图像 slider 。基本上是带有分页图像的 ScrollView 。

我需要点击并双击此 ImageSlider 来执行一些操作。单击可以正常工作,但不会触发双击选择器。

override func awakeFromNib() {
super.awakeFromNib()

let singleTap = UITapGestureRecognizer(target: self, action: #selector(singleTap(_:)))
singleTap.numberOfTapsRequired = 1
singleTap.cancelsTouchesInView = false
slideShowView.addGestureRecognizer(singleTap)


//Double tap recognizer
let doubleTap = UITapGestureRecognizer(target: self, action: #selector(doubleTap(_:)))
doubleTap.cancelsTouchesInView = false
doubleTap.numberOfTapsRequired = 2

slideShowView.addGestureRecognizer(doubleTap)

singleTap.require(toFail: doubleTap)

print("slideshow recognizers",slideShowView.gestureRecognizers!) }


func doubleTap(_ sender : UITapGestureRecognizer) {

print("doubletap")
}

func singleTap(_ sender : UITapGestureRecognizer) {

print("singleTap")
}

问候

编辑:你可以在这里看到我的日志,我也更改了我原来的帖子

 slideshow recognizers [<UITapGestureRecognizer: 0x17ec1670; state = Possible; view = <ImageSlideshow.ImageSlideshow 0x17ec0e30>; target= <(action=singleTap:, target=<Descubra.FeedDefaultCell 0x183cf800>)>; must-fail = {
<UITapGestureRecognizer: 0x17e763b0; state = Possible; view = <ImageSlideshow.ImageSlideshow 0x17ec0e30>; target= <(action=doubleTap:, target=<Descubra.FeedDefaultCell 0x183cf800>)>; numberOfTapsRequired = 2>
}>, <UITapGestureRecognizer: 0x17e763b0; state = Possible; view = <ImageSlideshow.ImageSlideshow 0x17ec0e30>; target= <(action=doubleTap:, target=<Descubra.FeedDefaultCell 0x183cf800>)>; numberOfTapsRequired = 2; must-fail-for = {
<UITapGestureRecognizer: 0x17ec1670; state = Possible; view = <ImageSlideshow.ImageSlideshow 0x17ec0e30>; target= <(action=singleTap:, target=<Descubra.FeedDefaultCell 0x183cf800>)>>
}>]

singleTap

最佳答案

为了使单击和双击手势协同工作,系统在看到单个手势时需要知道它是真正的单击手势还是双击手势的前半部分。它要么必须了解 future (这将是一个非常有值(value)的功能),要么必须等待,看看接下来会发生什么。告诉它等等看...

singleTap.requireGestureRecognizerToFail(doubleTap)

关于ios - 在 UIGestureRecognizer 中双击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41747144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com