我想分享/解释问题的解决方案。也就是说,我还想指出,hatfinch 的输入将我引向了正确的方向。非常非常感谢你,伙计!
尝试将视图/滚动视图作为覆盖顶层时的问题是顶层不知道它的“下一个响应者”。将视图/滚动视图作为底层视图将解决此问题。您可能需要微调该底层滚动视图中任何滚动视图的触摸行为以使行为正确(例如设置最大触摸次数)
解决方案是将 UIScrollview 子类化,覆盖此方法
覆盖 touchesBegan: 和其他触摸方法如下(参见 user1085093 答案),并将其作为底层视图添加到 ipad 屏幕。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
// If not dragging, send event to next responder
if (!self.dragging){
[self.nextResponder touchesBegan: touches withEvent:event];
}
else{
[super touchesBegan: touches withEvent: event];
}}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
// If not dragging, send event to next responder
if (!self.dragging){
[self.nextResponder touchesMoved: touches withEvent:event];
}
else{
[super touchesMoved: touches withEvent: event];
}}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
// If not dragging, send event to next responder
if (!self.dragging){
[self.nextResponder touchesEnded: touches withEvent:event];
}
else{
[super touchesEnded: touches withEvent: event];
}}
我像这样设置了滚动视图:
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);
}}
这个解决方案效果很好。另一种解决方案是像我最初打算的那样将滚动视图作为覆盖视图。如前所述,问题是让顶层视图知道它下面的视图(nextResponder)。要实现这一点,您必须继承 UIScrollview 并创建一个 UIResponder-property,您必须在您的 interface-builder 文件中或在运行时连接。这样,覆盖的滚动视图将知道谁是下一个响应者。
请看晨星的回答