我有一个垂直滚动的UIScrollView
. 我还想在其上处理水平平移,同时允许默认的垂直滚动行为。我UIView
在滚动视图上放置了一个透明的,并添加了一个平移手势识别器。这样我就可以很好地得到平底锅,但是滚动视图不会收到任何手势。
我已经实现了以下UIPanGestureRecognizerDelegate
方法,希望将我的手势识别器限制为仅水平平移,但这并没有帮助:
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
// Only accept horizontal pans here.
// Leave the vertical pans for scrolling the content.
CGPoint translation = [gestureRecognizer translationInView:self.view];
BOOL isHorizontalPan = (fabsf(translation.x) > fabsf(translation.y));
return isHorizontalPan;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return (otherGestureRecognizer == _scrollView.panGestureRecognizer);
}