Reputation: 14418
How do I check if a pinch has been released? I tried
- (IBAction)resizeImage:(UIPinchGestureRecognizer *)sender
{
if (sender.delaysTouchesEnded)
//here
}
and it didn't work out
Upvotes: 1
Views: 1469
Reputation: 2375
UIAdam's answer worked for me...
if([(UIPinchGestureRecognizer *)sender state] == UIGestureRecognizerStateEnded)
{
}
This is my complete method with zoom (CGAffineTransformScale)
(self.pictureCard01 is a UIView subclass which I'm pinching)
- (IBAction)PinchGesture01:(UIGestureRecognizer *)sender {
CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
if (factor > 2) {
factor = 2;
}
else if (factor < 1) {
factor = 1;
}
[UIView animateWithDuration:2 delay:0.0 options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
self.pictureCard01.transform = CGAffineTransformScale(CGAffineTransformIdentity, factor, factor);
}
completion:nil];
if([(UIPinchGestureRecognizer *)sender state] == UIGestureRecognizerStateEnded)
{
[self performSelector:@selector(resize:) withObject:self.pictureCard01 afterDelay:2];
}
}
-(void)resize:(UIView*)myview{
[UIView animateWithDuration:2 delay:0.0 options:UIViewAnimationOptionAllowAnimatedContent
animations:^{
myview.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
}
completion:nil];
}
Upvotes: 2
Reputation: 5313
You need to check for sender.state == UIGestureRecognizerStateEnded
and possibly sender.state == UIGestureRecognizerStateCancelled
Upvotes: 7