Method gestureRecognizer: shouldRecognizeSimultaneouslyWithGestureRecognizer: always It returns YES and the image processing works well, but… how to detect the end of all simultaneous gestures in order to reset the image?
.h file:
int handledGesturesCount;
.m file:
< /p>
- (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 (recog nizer.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];
}
}
}
In my application, I also use UIPinchGestureRecognizer, UIRotationGestu reRecognizer and UIPanGestureRecognizer to zoom, rotate and move the image.
Method gestureRecognizer: shouldRecognizeSimultaneouslyWithGestureRecognizer: always returns YES and the image processing effect is very good, but… how to detect the end of all simultaneous gestures in order to reset image?
A simple solution such as counting the gestures currently being processed, and taking action at the end of all these gestures?
.h file:
int handledGesturesCount;
.m file:
< /p>
- (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 {< br /> if (recognizer.state == UIGestureRecognizerStateBegan) {
handledGesturesCount += 1;
} else if (recognizer.state == UIGestureRecognizerStateEnded ||
recognizer.state == UIGestureRecognizerStateCancelled ||
recognizer.state == UIGestureRecognizerStateFailed)
{
handledGesturesCount -= 1;
if (handledGesturesCount == 0) {
[self resetImage];
}
}
}