在我的应用程序中,我同时使用UIPinchGestureRecognizer,UIRotationGestureRecognizer和UIPanGestureRecognizer进行缩放,旋转和移动图像. 方法gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:始终返回
方法gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:始终返回YES并且图像处理效果很好,但是……如何检测所有同时手势的结束,以便重置图像?
一个简单的解决方案如计算当前正在处理的手势,并在所有这些手势结束时采取行动?.h文件:
int handledGesturesCount;
.m文件:
- (id)init { (...) handledGesturesCount = 0; } // gesture handlers - the code for -pinch: repeats for -pan: and -rotate: - (void)pinch:(UIPinchGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateBegan) { handledGesturesCount += 1; } else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled || recognizer.state == UIGestureRecognizerStateFailed) { handledGesturesCount -= 1; if (handledGesturesCount == 0) { [self resetImage]; } } } - (void)pan:(UIPanGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateBegan) { handledGesturesCount += 1; } else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled || recognizer.state == UIGestureRecognizerStateFailed) { handledGesturesCount -= 1; if (handledGesturesCount == 0) { [self resetImage]; } } } - (void)rotate:(UIRotationGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateBegan) { handledGesturesCount += 1; } else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled || recognizer.state == UIGestureRecognizerStateFailed) { handledGesturesCount -= 1; if (handledGesturesCount == 0) { [self resetImage]; } } }