我正在寻找一种方法来实现以下内容:
- 有一个“主”滚动视图,其中包含顶部的全屏 UIView 和下方的全屏 UIScrollView
- 当用户滚动经过顶部的 UIView 时,底部的 scrollView 是可见的,并成为滚动事件的响应者
- 当用户尝试从底部 UIScrollView 向上滚动时,触摸会被重定向,因此他们控制“主”滚动视图并再次将 UIView 带入视图。
为了了解这是如何设置的,这是我当前的实现:
// Initialise components:
mainScreen = [[UIScreen mainScreen] bounds];
CGFloat screenHeight = mainScreen.size.height-20;
// Scroll View Controller
_scrollControl = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, screenHeight)];
_scrollControl.contentSize = CGSizeMake(320, 2*screenHeight); // Twice as big as the screen size for both views to fit
_scrollControl.backgroundColor = [UIColor clearColor];
_scrollControl.delegate = self;
// Top View
_topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, screenHeight)];
_topView.backgroundColor = [UIColor redColor];
[_scrollControl addSubview:_topView];
// Bottom View
_bottomView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, screenHeight, 320, screenHeight)];
_bottomView.backgroundColor = [UIColor yellowColor];
_bottomView.contentSize = CGSizeMake(320, 2*screenHeight);
_bottomView.delegate = self;
UILabel *imageLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 40, 120, 700)];
imageLabel.backgroundColor = [UIColor greenColor];
[_bottomView addSubview:imageLabel];
[_scrollControl addSubview:_bottomView];
// Add to main view
[self.view addSubview:_scrollControl];
我试图使用委托方法来达到预期的效果,但是在切换到底部滚动视图之前,我似乎无法阻止“主”滚动视图滚动。