我想分享/解释这个问题的解决方案。也要指出,Hatfinch的输入引导了我正确的方向。非常感谢你!
当试图将视图/滚动视图作为覆盖顶层时,问题在于顶层不知道它的“下一响应者”。 将视图/滚动视图放置在底层视图中将解决此问题。 您可能需要微调底层滚动视图内任何滚动视图的触摸行为,以使行为正确(例如设置最大触摸数量)。
解决方案是子类化UIScrollview,重写以下方法
(请参见user1085093的答案)并将其添加为iPad屏幕的底层视图。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if (!self.dragging){
[self.nextResponder touchesBegan: touches withEvent:event];
}
else{
[super touchesBegan: touches withEvent: event];
}}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
if (!self.dragging){
[self.nextResponder touchesMoved: touches withEvent:event];
}
else{
[super touchesMoved: touches withEvent: event];
}}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if (!self.dragging){
[self.nextResponder touchesEnded: touches withEvent:event];
}
else{
[super touchesEnded: touches withEvent: event];
}}
我已经按照如下方式设置了ScrollView:
我这样设置了ScrollView:
TopLayerScrollView *newScrollView = [[TopLayerScrollView alloc] init];
[newScrollView setBackgroundColor:[UIColor clearColor]];
[newScrollView setFrame:self.tabBarController.view.frame];
[newScrollView setContentSize:dualScreenViewController.scrollContent.contentSize];
newScrollView.showsHorizontalScrollIndicator = NO;
newScrollView.showsVerticalScrollIndicator = NO;
newScrollView.delegate = self;
newScrollView.bounces = NO;
[newScrollView scrollsToTop];
newScrollView.panGestureRecognizer.minimumNumberOfTouches = 2;
self.topLayerScrollView = newScrollView;
[newScrollView release];
[self.tabBarController.view removeFromSuperview];
[topLayerScrollView addSubview:self.tabBarController.view];
[window addSubview:topLayerScrollView];
[topLayerScrollView bringSubviewToFront:self.tabBarController.view];
底层滚动视图的代理方法:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.dragging || scrollView.tracking)
{
[dualScreenViewControlleremphasized text.scrollContent setContentOffset:CGPointMake(scrollView.contentOffset.x, scrollView.contentOffset.y) animated:NO];
self.tabBarController.view.frame = CGRectMake(scrollView.contentOffset.x, scrollView.contentOffset.y, self.tabBarController.view.frame.size.width, self.tabBarController.view.frame.size.height);
}}
这个解决方案非常好。
另一个解决方案是将scrollview作为一个覆盖的视图,如我最初所想。问题在于让顶层视图知道位于其下面的视图(nextResponder)。为了实现这一点,您必须子类化UIScrollview并创建一个UIResponder属性,您必须在界面构建器文件或运行时期间连接。这样,覆盖的scrollview就会知道下一个响应者是谁。
请参见morningstar的答案
touches...
方法来处理下一个响应者或其他对象。该视频中还提供了解决方案。 - Oleksii Nezhyborets