我有一个用于缩放视图的 UIPinchGestureRecognizer 的处理程序方法。我想要做到的是,当屏幕上有两次触摸以进行捏合手势时,如果抬起手指,剩下的手指将由平移手势识别器管理。有没有办法做到这一点?我想不出一种将一个手势从一个处理程序传递给另一个处理程序的正确方法。
问问题
1057 次
1 回答
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;
}
这将使两个处理程序都被触发,因此当您释放其中一个手指时它会平移,但是当您同时拥有它们时它会捏住。
于 2013-04-17T06:22:21.220 回答