iOS嵌套的UIScrollView没有响应

iOS嵌套的UIScrollView没有响应,ios,uiscrollview,nested,Ios,Uiscrollview,Nested,我一直在搜索如何嵌套UIScrollView。 看起来应该和使用容器滚动视图的addSubview:添加内部滚动视图一样简单。我有一切显示在视觉上正确,但功能的内部滚动视图是不存在的,尽管提供了适当的框架和内容大小。 下面的代码显示了到目前为止我所拥有的。只有外部滚动视图会滚动。我想让外部滚动视图控制从左到右的滚动,每个内部滚动视图控制其相关页面内容的垂直滚动 self.containerScroll = [[UIScrollView alloc]init]; self.containerScr

我一直在搜索如何嵌套UIScrollView。 看起来应该和使用容器滚动视图的addSubview:添加内部滚动视图一样简单。我有一切显示在视觉上正确,但功能的内部滚动视图是不存在的,尽管提供了适当的框架和内容大小。 下面的代码显示了到目前为止我所拥有的。只有外部滚动视图会滚动。我想让外部滚动视图控制从左到右的滚动,每个内部滚动视图控制其相关页面内容的垂直滚动

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];
看起来内容的高度设置为1。如果子项大于其父项,则无法正常工作(按钮的工作原理相同)


另外,确保您知道在委托方法中处理的是哪个scrollview。所有ScrollView都将以相同的方法处理,这可能会给您带来问题。

我尝试将容器滚动视图的内容大小设置为0,1,==subscroll,subscroll。更改内容大小并没有什么不同。子滚动视图仍然不滚动。容器的内容大小应为所有子视图的宽度和子视图的可见高度。子视图的内容大小应该是容器的宽度(而不是内容宽度)及其内容的高度。如果内容大小等于实际大小,则ScrollView不会滚动。因此,如果子视图的高度大于容器的高度,或者子视图的高度等于其内容的高度,则不会滚动。我发现了问题。添加到子滚动视图的页面正在使用自动布局。将此类视图添加到滚动视图会导致滚动视图尝试根据添加视图的大小计算其内容大小。由于我在手动定义内容大小后添加了子视图,因此该手动定义被覆盖。
self.containerScroll.contentSize = CGSizeMake(self.containerScroll.bounds.size.width*3,1);