【问题标题】:touchesMoved being called on single Tap with iPhone 6s and onwardstouchesMoved 在 iPhone 6s 及更高版本上单击即可调用
【发布时间】:2016-10-26 16:19:34
【问题描述】:

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

在 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,我该如何解决?

【问题讨论】:

    标签: ios objective-c touchesmoved


    【解决方案1】:

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

    两种可能的解决方案。

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

    【讨论】:

    • 我仔细检查了我是否没有移动我的触摸。在旧设备中没有问题,但这里有额外的代表。 TapRecognizer 可能会解决这个问题,但是是否可以使用触摸代理解决这个问题?
    猜你喜欢
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2015-03-04
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多