我想分享/解释问题的解决方案。也就是说,我还想指出,帽翅雀的输入引导我走向了正确的方向。非常非常感谢你,伙计!
尝试将视图/滚动视图作为覆盖播放器时的问题是播放器不知道其“下一个响应者”。将视图/滚动视图作为底层视图将解决这个问题。
您可能需要微调该底层滚动视图中任何滚动视图的触摸行为以获得正确的行为(例如设置最大触摸次数)
解决方案是子类化 UIScrollview,重写此方法重写touchesBegan:和其他触摸方法如下 https://stackoverflow.com/questions/7439273/uiscrollview-prevents-touchesbegan-touchesmoved-touchesended-on-view-controlle(参见用户 1085093 的回答),并将其添加为 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];
底层scrollview的委托方法:
- (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);
}}
这个解决方案效果很好。
另一个解决方案是按照我最初的意图将滚动视图作为覆盖视图。如前所述,问题是让 toplayer 视图了解其下面的视图(nextResponder)。要实现此目标,您必须子类化 UIScrollview 并创建一个 UIResponder 属性,您必须在界面生成器文件中或在运行时连接。这样覆盖的滚动视图就会知道谁是下一个响应者。请看晨星的回答 https://stackoverflow.com/questions/7439273/uiscrollview-prevents-touchesbegan-touchesmoved-touchesended-on-view-controlle