【发布时间】:2018-01-02 07:55:54
【问题描述】:
在我的应用程序中,我需要根据用户点击图像的次数在点击手势上运行不同的功能。
我有一个需要点击 1 次的点击手势识别器。
我的第二个轻击手势识别器需要轻击 2 次。但是,如果我点击它 2 次,每个点击手势的两个函数都会被调用。
有没有办法做到这一点,让这两个函数可以分别调用,互不干扰?
问题:如果我点击图像两次,它会同时调用 goWatchVideo 函数和 onDoubleTap 函数。我想避免这种情况。
// Gesture that requires 1 tap
let tapToWatch = UITapGestureRecognizer(target: self, action: #selector(goWatchVideo))
tapToWatch.numberOfTapsRequired = 1
postVideoView.addGestureRecognizer(tapToWatch)
// Gesture that requires 2 taps
let doubleLike = UITapGestureRecognizer(target: self, action:#selector(self.onDoubleTap))
doubleLike.numberOfTapsRequired = 2
postVideoView.addGestureRecognizer(doubleLike)
// Tried to set them up for failures
tapToWatch.require(toFail: doubleLike)
doubleLike.require(toFail: tapToWatch)
【问题讨论】:
-
确保这一点 ->
postVideoView .isUserIntraction = true -
这不是问题。我更新了描述以进一步澄清问题
-
stackoverflow.com/questions/8876202/… 您应该只将
require(toFail:)放在带有双击参数的单击上。
标签: ios iphone swift uitapgesturerecognizer