在触摸移动之后,有时触摸未触及触摸取消

Cod*_*ger 1 cocoa-touch objective-c touches ios

我在我的应用程序中有一个圆形视图,我在圆形视图中移动一些像图形的对象,它在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;
}
Run Code Online (Sandbox Code Playgroud)

我从昨晚开始就被困在这里,所以任何帮助都将受到赞赏.

提前致谢.

amo*_*tes 5

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

NSTimer可以帮助我们

但是,我觉得我们可以通过添加设置解决这一/替换NSTimer实例,同时touchesMoved调用,我们可以复位定时器上touchesEndedtouchesCancelled.因此,在任何一种情况下,您touchesEnded或未touchesCancelled调用的计时器都将完成该工作,您的重置逻辑将按预期工作.

演示源代码

- (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
}
Run Code Online (Sandbox Code Playgroud)