我在 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/