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.
我希望在我的UIPinchGestureRecognizer完成捏合手势时收到回调。此外,很高兴知道完成的手势是放大还是缩小。
Does anyone know a method to use? Or the approach to do?
有谁知道使用的方法?还是做的方法呢?
Thanks!
3 个解决方案
#1
13
Another approach instead of overriding touchesEnded:, is that you could just check the state of the gesture recognizer in your target handler method.
替代覆盖touchesEnded:的另一种方法是,您可以在目标处理程序方法中检查手势识别器的状态。
-(void)handlePinchGesture:(UIGestureRecognizer*)gestureRecognizer {
if(UIGestureRecognizerStateEnded == [gestureRecognizer state]){
// do something
}
}
#2
1
You can know if it was a zoom in or out by the scale property of the UIPinchGestureRecognizer.
你可以通过UIPinchGestureRecognizer的scale属性知道它是放大还是缩小。
Just overrride it's touchesEnded: method to get a callback (and the call some other method if you wish).
只需覆盖它的touchesEnded:获取回调的方法(如果你愿意,可以调用其他方法)。
#3
0
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.
不需要子类化的最佳方法是检查动作处理程序中手势识别实例上的“状态”属性。状态将在手势生命周期的所有阶段发生变化。您正在寻找的状态更改是UIGestureRecognizerStateEnded。检查UIGestureRecognizerStateCancelled也是一种好习惯。
#1
13
Another approach instead of overriding touchesEnded:, is that you could just check the state of the gesture recognizer in your target handler method.
替代覆盖touchesEnded:的另一种方法是,您可以在目标处理程序方法中检查手势识别器的状态。
-(void)handlePinchGesture:(UIGestureRecognizer*)gestureRecognizer {
if(UIGestureRecognizerStateEnded == [gestureRecognizer state]){
// do something
}
}
#2
1
You can know if it was a zoom in or out by the scale property of the UIPinchGestureRecognizer.
你可以通过UIPinchGestureRecognizer的scale属性知道它是放大还是缩小。
Just overrride it's touchesEnded: method to get a callback (and the call some other method if you wish).
只需覆盖它的touchesEnded:获取回调的方法(如果你愿意,可以调用其他方法)。
#3
0
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.
不需要子类化的最佳方法是检查动作处理程序中手势识别实例上的“状态”属性。状态将在手势生命周期的所有阶段发生变化。您正在寻找的状态更改是UIGestureRecognizerStateEnded。检查UIGestureRecognizerStateCancelled也是一种好习惯。