开发者

How can I find out when a pinch gesture is finished (UIGestureRecognizer)

开发者 https://www.devze.com 2023-01-08 07:00 出处:网络
I want to get a callback when my UIPinchGestureRecognizer finished a pinch-gesture. Moreover it would be great to know if the finished gesture was a zoom in or 开发者_如何学编程a zoom out.

I want to get a callback when my UIPinchGestureRecognizer finished a pinch-gesture. Moreover it would be great to know if the finished gesture was a zoom in or 开发者_如何学编程a zoom out.

Does anyone know a method to use? Or the approach to do?

Thanks!


Another approach instead of overriding touchesEnded:, is that you could just check the state of the gesture recognizer in your target handler method.

  -(void)handlePinchGesture:(UIGestureRecognizer*)gestureRecognizer {    
    if(UIGestureRecognizerStateEnded == [gestureRecognizer state]){
      // do something
    }
  }


You can know if it was a zoom in or out by the scale property of the UIPinchGestureRecognizer.

Just overrride it's touchesEnded: method to get a callback (and the call some other method if you wish).


The best approach which does not require subclassing is to examine the "state" property on the gesture recognized instance in your action handler. The state will change during all phases of the lifecycle of the gesture. The state change you're looking for is UIGestureRecognizerStateEnded. It is also good practice to check for UIGestureRecognizerStateCancelled as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消