0
我一直在寻找如何嵌套UIScrollViews。 它看起来应该像使用addSubview:容器滚动视图添加内部滚动视图一样简单。我已将所有内容显示在视觉上正确,但内部滚动视图的功能不存在,尽管为它们提供了适当的帧和内容大小。 我下面的代码显示了我到目前为止所拥有的。只有外滚动视图滚动。我需要它,以便外部滚动视图控制从左到右滚动,并且每个内部滚动视图控制其相关页面内容的垂直滚动。iOS嵌套的UIScrollViews没有响应
self.containerScroll = [[UIScrollView alloc]init];
self.containerScroll.frame = CGRectMake(0,(self.headerView.frame.size.height + self.pageControl.frame.size.height),screenWidth, (screenHeight - (self.headerView.frame.size.height + self.pageControl.frame.size.height)));
self.containerScroll.backgroundColor = [UIColor clearColor];
self.containerScroll.alpha = 1;
self.containerScroll.pagingEnabled = YES;
self.containerScroll.contentSize = CGSizeMake(self.containerScroll.bounds.size.width*3,1);
self.containerScroll.bounces = NO;
self.containerScroll.delegate = self;
[self.view addSubview:self.containerScroll];
self.page1Scroll = [[UIScrollView alloc]init];
self.page1Scroll.frame = CGRectMake(0,0,self.containerScroll.bounds.size.width,self.containerScroll.bounds.size.height);
self.page1Scroll.backgroundColor = [UIColor redColor];
self.page1Scroll.alpha = 1;
[self.page1Scroll addSubview:self.feedPageVC.view];
self.page1Scroll.contentSize = CGSizeMake(320,500);
self.page1Scroll.delegate = self;
[self.containerScroll addSubview:self.page1Scroll];
self.page2Scroll = [[UIScrollView alloc]init];
self.page2Scroll.frame = CGRectMake(self.containerScroll.bounds.size.width,0,self.containerScroll.bounds.size.width,self.containerScroll.bounds.size.height);
self.page2Scroll.backgroundColor = [UIColor greenColor];
self.page2Scroll.delegate = self;
[self.containerScroll addSubview:self.page2Scroll];
self.page3Scroll = [[UIScrollView alloc]init];
self.page3Scroll.frame = CGRectMake(self.containerScroll.bounds.size.width*2,0,self.containerScroll.bounds.size.width,self.containerScroll.bounds.size.height);
self.page3Scroll.backgroundColor = [UIColor blueColor];
[self.page3Scroll addSubview:self.detailsPageVC.view];
self.page3Scroll.contentSize = CGSizeMake(320,500);
self.page3Scroll.delegate = self;
[self.containerScroll addSubview:self.page3Scroll];
我尝试将容器滚动视图的内容大小设置为0,1,== subscroll, subscroll。改变内容大小并没有什么不同。子滚动视图仍然不会滚动。 –
Sethypie
容器的内容大小应该是所有子视图的宽度和子视图的可见高度。子视图的内容大小应该是容器的宽度(而不是内容宽度)和内容的高度。如果内容大小等于实际大小,滚动视图将不会滚动。因此,如果您的子视图的高度高于容器的高度,或者您的子视图的高度等于其内容高度,则不会滚动。 – JeffRegan
我发现了这个问题。添加到子滚动视图的页面正在使用自动布局。将这样的视图添加到滚动视图会导致滚动视图尝试根据添加的视图的大小计算其内容大小。由于我在手动定义内容大小之后添加了子视图,因此该手动定义被覆盖。 – Sethypie