gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 03:09:50 24 4
gpt4 key购买 nike

我有一个自定义 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com