touchesEnded 和 touchesCancelled 都不会在 touchesMoved 之后调用

Neither touchesEnded nor touchesCancelled not called sometimes after touchesMoved

我的应用程序中有一个圆形视图,我正在该圆形视图中移动一些对象,例如图形,它在 90% 的情况下工作正常,但在某些情况下它没有调用 TouchEnded,我的重置图形代码是在 TouchEnded 方法中,所以它在下面的某个时候卸载是我的触摸委托方法代码。

#pragma mark - Touch Events For Rotation of GRAPH

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch* touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];

    prevAngle = [Utilities angleBetweenPoint:touchPoint toPoint:self.view.center];
/// convert negative angle into positive angle
    if(prevAngle < 0){
        prevAngle = PI_DOUBLE + prevAngle;
    }

    //
    [_viewStaticRadialPart hideToolTip];
}
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
    CGFloat diffAngle, tempCurAngle, tempPrevAngle, curTransformAngle, newTransformAngle;

    NSLog(@"touchesMoved");
// Get the only touch (multipleTouchEnabled is NO)
    UITouch* touch = [touches anyObject];
    // Track the touch
    CGPoint touchPoint = [touch locationInView:self.view];


    curAngle = [Utilities angleBetweenPoint:touchPoint toPoint:self.view.center];

    /// convert negative angle into positive angle
    if(curAngle < 0){
        curAngle = PI_DOUBLE + curAngle;
    }
        prevAngle = curAngle;
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self resetViewsOnceRotationStops];


}
- (void)touchesCancelled:(nullable NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event
{
    [resetViewsAfterTouchStops invalidate];
    resetViewsAfterTouchStops = nil;
}

我从昨晚起就被困在这里,所以我们将不胜感激。

提前致谢。

尝试删除该视图上的 UIGestureRecognizer 个对象(如果您正在使用)。 UIGestureRecognizer 对象干扰触摸事件生命周期。

我从核心层面不知道这个问题的原因。

但是NSTimer可以在

中帮助我们

但我觉得我们可以通过在调用 touchesMoved 时添加设置/替换 NSTimer 实例来解决这个问题,我们可以在 touchesEndedtouchesCancelled 上重置该计时器。因此,在任何一种情况下,您的 touchesEndedtouchesCancelled 未调用计时器都会完成这项工作,并且您的重置逻辑会按预期工作。

演示源代码

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
    NSLog(@"touchesMoved");

    //Timer re-initialize code here
    if (resetViewsAfterTouchStops) {

         [resetViewsAfterTouchStops invalidate];
         resetViewsAfterTouchStops = nil;
    }

    resetViewsAfterTouchStops =  [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(resetViewsOnceRotationStops) userInfo:nil repeats:NO];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    isTouched = NO;
    [resetViewsAfterTouchStops invalidate];
    resetViewsAfterTouchStops = nil;

    [self resetViewsOnceRotationStops];
    [self setUserInteractionOnSectorsAs:YES];
}

- (void)touchesCancelled:(nullable NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event
{
    NSLog(@"touchesCancelled");
    if(resetViewsAfterTouchStops)
    {
         [self resetViewsOnceRotationStops];
         [self setUserInteractionOnSectorsAs:YES];
    }

    [resetViewsAfterTouchStops invalidate];
    resetViewsAfterTouchStops = nil;
}

- (void) resetViewsOnceRotationStops
{
    //your reset code will be place here
}