gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:48:44 24 4
gpt4 key购买 nike

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

#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;
}

我从昨晚开始就被困在这里,所以任何帮助都将不胜感激。

提前致谢。

最佳答案

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

但是NSTimer可以帮助我们

但我觉得我们可以通过添加设置/替换来解决这个问题 NSTimer实例而 touchesMoved调用,我们可以在 touchesEnded 上重置该计时器和 touchesCancelled .因此,无论哪种情况,您的 touchesEndedtouchesCancelled not called timer 将完成这项工作,并且您的重置逻辑按预期工作。

演示源代码

- (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
}

关于ios - touchesEnded 和 touchesCancelled 都不会在 touchesMoved 之后调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38495903/

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