1
我正在使用UISwipeGestureRecognizer。我有以下問題。當我觸摸一個正方形時,它開始旋轉。當我停止觸摸時,它停止旋轉。我想用計時器,當它通過10秒的觸摸時,廣場自動停止旋轉。我找到了一個解決方案,但我認爲這不是乾淨的。 你有什麼想法,從方法自動傳遞:UISwipeGestureRecognizer:如何強制touchesMoved停止並進入touchesEnd
- (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