2013-07-22 55 views
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
self.containerScroll.contentSize = CGSizeMake(self.containerScroll.bounds.size.width*3,1); 

看起來像你的內容的高度設置爲1,如果一個孩子比其母公司大,這將無法正常工作(工作原理是一樣的按鈕)。

此外,請確保您知道您在委託方法中處理哪個滾動視圖。所有的滾動視圖都將以相同的方法處理,並且可能會導致問題。

+0

我嘗試將容器滾動視圖的內容大小設置爲0,1,== subscroll, subscroll。改變內容大小並沒有什麼不同。子滾動視圖仍然不會滾動。 – Sethypie

+0

容器的內容大小應該是所有子視圖的寬度和子視圖的可見高度。子視圖的內容大小應該是容器的寬度(而不是內容寬度)和內容的高度。如果內容大小等於實際大小,滾動視圖將不會滾動。因此,如果您的子視圖的高度高於容器的高度,或者您的子視圖的高度等於其內容高度,則不會滾動。 – JeffRegan

+2

我發現了這個問題。添加到子滾動視圖的頁面正在使用自動佈局。將這樣的視圖添加到滾動視圖會導致滾動視圖嘗試根據添加的視圖的大小計算其內容大小。由於我在手動定義內容大小之後添加了子視圖,因此該手動定義被覆蓋。 – Sethypie