我编写了一个UIScrollView子类,用于滚动一系列UITableViews。见下图:

如您所见,我有几个垂直滚动的UITableViews,它们在父UIScrollView中水平滚动。一切都很好。然而,应用程序有许多全局手势。例如,如果我用两个手指在给定的方向上滑动,我就会将UIView转换到应用程序的另一个部分。但是,如果我在滚动视图和/或其子表视图的顶部做手势,它们自然会滚动它们的内容。这看起来不太好,会导致一些布局问题。
我想弄清楚的是,当用户用两个手指和两个手指触摸任何地方时,如何禁用UIScrollView及其子UITableViews上的所有滚动。我试过重写touchesBegan,touchesEnded,touchesShouldCancel等.但我搞错了。任何帮助都是非常感谢的。
下面是我的手势处理代码:
UISwipeGestureRecognizer *twoFingerSwipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerSwipe:)];
[twoFingerSwipeUp setNumberOfTouchesRequired:2];
[twoFingerSwipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
[twoFingerSwipeUp setDelegate:self];
// 'self' is the superview of the UIScrollView, which is a UIView.
[self addGestureRecognizer:twoFingerSwipeUp];
[twoFingerSwipeUp release];
// ... repeat the above code for up, down, left, right gestures ...
- (void)handleTwoFingerSwipe:(UISwipeGestureRecognizer*)swipeGesture {
switch ([swipeGesture direction]) {
case UISwipeGestureRecognizerDirectionUp:
[self changeToView:viewAbove];
break;
case UISwipeGestureRecognizerDirectionDown:
[self changeToView:viewBelow];
break;
case UISwipeGestureRecognizerDirectionRight:
[self changeToView:viewToTheRight];
break;
case UISwipeGestureRecognizerDirectionLeft:
[self changeToView:viewToTheLeft];
break;
}
}发布于 2011-11-21 20:19:28
尝试在所有滚动视图和表视图上设置panGestureRecognizer.maximumNumberOfTouches = 1 (仅iOS 5)。
发布于 2011-11-22 11:17:47
如果使用双指滑动识别器,则要求滚动视图的识别器(包括表视图--它们也是滚动视图)在双指识别器识别其手势时失败。
[[scrollView panGestureRecognizer] requireGestureRecognizerToFail: twoFingerRecogniser];对每个滚动视图和表视图迭代上述代码。
(“识别器”是英式英语,而不是拼写错误。)
希望这能有所帮助。:-)
发布于 2011-11-28 13:02:34
编写以下代码: scrollView.minimumZoomScale=1.0;scrollView.maximumZoomScale=1.0;scrollView.delegate self];
下面是scrollViewDelegate方法:-
-(UIView*)viewForZoomingInScrollView:(UIScrollView *)aScrollView{返回aScrollView;}
https://stackoverflow.com/questions/8073078
复制相似问题