ios - touchesMoved 在 iPhone 6s 及以后的设备上被调用

标签 ios objective-c touchesmoved

我有一个自定义 UIButton 并且我在自定义按钮类中实现了触摸委托(delegate)。

在 iPhone 6 Plus 之前一切正常。它上面的所有设备,如 iPhone 6s 和 7 都在制造问题。

当我单击一个按钮时,touchesBegan 会按预期调用,但 touchesMoved 也会被调用,这会在我的代码中产生问题。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
     _firstTouch = [[touches anyObject]locationInView:self];
     _isTapped = YES;

     [self.nextResponder.nextResponder  touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
   _isTapped = NO;

   [self.nextResponder.nextResponder touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if (_isTapped){
    //Functionality
}

为什么在这些设备上调用了 touchesMoved,我该如何解决?

最佳答案

可能是高分辨率的屏幕对任何运动都更敏感。当您敲击时,您实际上可能只是在滚动手指,使其看起来像是一个小 Action 。

两种可能的解决方案。

  1. 在您的 touchesMoved: 方法中检查触摸移动了多远。如果这是一个非常小的举动,为了您的 _isTapped 检查目的而忽略它。
  2. 不要覆盖touches... 方法,而是使用UITapGestureRecognizer。让它完成确定什么是水龙头什么不是水龙头的所有艰苦工作。这将使您的代码更加简单。

关于ios - touchesMoved 在 iPhone 6s 及以后的设备上被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40267378/

相关文章:

ios - TouchesMoved 与 UITouch

objective-c - 在 UIView 而非 UIImageView 上自由手绘

ios - nativescript 模态对话框透明度

ios - Xcode 9 - "Fixed Width Constraints May Cause Clipping"和其他本地化警告

objective-c - 无法获取 HTML 代码 AFNetworking 2.0

iphone - UIAlertView 的 TextField 的自动大写

ios - Swift 中来自 nib 的自定义 UITableViewCell

ios - Podfile中link_with的真正含义是什么?

iphone - Amazon S3 通过 iOS 应用程序上传完成百分比

ios - 相对于手指拖动 UIVIew