我有一个UIPinchGestureRecognizer的处理程序方法,用于缩放视图。我正在努力做到这一点,以便在屏幕上进行两次触摸以进行捏合手势,并且如果手指被抬起,则剩余的手指将由平移手势识别器管理。有没有办法做到这一点?我想不出将一个手势从一个处理程序传递到另一个处理程序的正确方法。
答案 0 :(得分:0)
这应该很简单。创建两个手势识别器。 UIPinchGestureRecognizer和UIPanGestureRecognizer。不要忘记成为两者的代表!
pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleHandler:)];
[pinchRecognizer setDelegate:self];
[pinchRecognizer setDelaysTouchesBegan:NO];
[pinchRecognizer setDelaysTouchesEnded:NO];
[pinchRecognizer setCancelsTouchesInView:NO];
panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panHandler:)];
[panRecognizer setMaximumNumberOfTouches:2];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[panRecognizer setDelaysTouchesBegan:NO];
[panRecognizer setDelaysTouchesEnded:NO];
[panRecognizer setCancelsTouchesInView:NO];
现在实现手势委托的以下方法。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
这将使两个处理程序都被触发,这样当你释放其中一个手指时它会平移,但当你同时拥有它们时它会捏住。