【问题标题】:Adding at UITapGestureRecognizer (double tap) to a UIButton slows down setting the button image as selected在 UITapGestureRecognizer(双击)添加到 UIButton 会减慢将按钮图像设置为选中状态
【发布时间】:2012-08-21 19:07:25
【问题描述】:

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

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

如果我摆脱双击手势,不会有延迟。

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

【问题讨论】:

    标签: ios uibutton uitapgesturerecognizer


    【解决方案1】:

    据推测,它会等到可以确定您没有双击时,才会识别出按钮想要的单击。 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 2019-09-14
      • 1970-01-01
      相关资源
      最近更新 更多