ios - 将 UITapGestureRecognizer(双击)添加到 UIButton 会减慢将按钮图像设置为选中的速度

标签 ios uibutton uitapgesturerecognizer

我在 UIButton 上有双击手势。对于未选中和选中状态,我有两个不同的背景图像。

所有功能都可用,但当我触摸按钮时,更改所选状态的背景图像会出现延迟。

如果我摆脱双击手势,就没有延迟。

我怎样才能摆脱这种延迟并仍然保持双击手势?

最佳答案

据推测,它会一直等到它可以确定您没有双击,然后才识别出按钮想要的单击。 UIView 中可能内置了一些东西来帮助手势识别器消除歧义,而 UIButton 正在使用识别器来完成它的工作。

考虑到这一点,您是否考虑过基于现有的 UIControl 标注合成双击?所以例如你会:

- (IBAction)buttonWasTapped:(id)sender // wired up to the button
{
    NSTimeInterval timeNow = [NSDate timeIntervalSinceReferenceDate];
    NSTimeInterval difference = timeNow - timeThen;
    timeThen = timeNow; // an instance variable

    if(difference < kYourAllowedTimeBetweenTaps)
    {
        timeThen = 0.0; // to avoid capture of triple taps, etc
        [self buttonWasDoubleTapped:sender];
        return;
    }

    // do normal single tap processing here, if any
}

关于ios - 将 UITapGestureRecognizer(双击)添加到 UIButton 会减慢将按钮图像设置为选中的速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12061409/

相关文章:

swift - 将 UITapGestureRecognizer 添加到 JSQMessageViewController 头像

ios - Swift 手动旋转 View Controller

ios - UIButton 自动布局大小设置

ios - 在展开 UIButton 设置标题的可选值时意外发现 nil

iOS 为什么不能方法 collectionView :didSelectItemAtIndexPath: be called from UITapGestureRecognizer?

iphone - 识别 UITapGestureRecogniser 的多个 UILabels 点击

ios - 使用 NSTimer 的周期性本地通知不起作用

iphone - 核心数据 - 为什么不自动设置反向关系?

iphone - UILongPressGestureRecognizer 标签? - iPhone

ios - layer.borderColor 和更多属性不起作用