我正在使用 UISwipeGestureRecognizer。我有以下问题。当我触摸一个正方形时,它开始旋转。当我停止触摸它时,它停止旋转。我想做一个计时器,当它通过 10 秒的触摸时,正方形自动停止旋转。我找到了一个解决方案,但我认为它不干净。您是否有任何想法从方法中自动传递:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
到方法:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
我正在使用这段代码:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
if ([self state] == UIGestureRecognizerStatePossible) {
[self setState:UIGestureRecognizerStateBegan];
NSLog(@"Algo Began");
}
if ([[event touchesForGestureRecognizer:self] count] > 1)
{
[self setState:UIGestureRecognizerStateCancelled ];
NSLog(@"Algo Fail");
}
if (chowMuch==50) {
//[self setState:UIGestureRecognizerStateFailed ];
[self setState:UIGestureRecognizerStateRecognized ];
NSLog(@"Algo falla que pasara");
}
else {
[self setState:UIGestureRecognizerStateChanged];
NSLog(@"Algo changed");
}
}
该方法一直在执行NSLog(@"Algo changed")
,这意味着当我触摸正方形时,状态为 UIGestureRecognizerStateChanged,但当chowMuch
为 50 时,此完成。你有什么想法可以传递给touchesEnded