检查是否在UIPinchGestureRecognizer中释放了夹点

时间:2012-01-13 00:49:44

标签: iphone objective-c ios ipad

如何检查是否释放了夹点?我试过了

- (IBAction)resizeImage:(UIPinchGestureRecognizer *)sender
{
   if (sender.delaysTouchesEnded)
   //here
}

并没有成功

2 个答案:

答案 0 :(得分:7)

您需要检查sender.state == UIGestureRecognizerStateEndedsender.state == UIGestureRecognizerStateCancelled

答案 1 :(得分:2)

UIAdam的回答对我有用......

    if([(UIPinchGestureRecognizer *)sender state] == UIGestureRecognizerStateEnded)
    {

    }

这是我完整的缩放方法(CGAffineTransformScale)

(self.pictureCard01是我正在捏的UIView子类)

   - (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];
                }