2012-01-16 44 views
0

我正在使用多個UIScrollViews在另一個之上,我使用UISegmentedControl來管理哪一個是活動的,我的問題是,一旦我設置了UIScrollView的位置並轉到另一個,當我嘗試並返回我只能控制最後選擇的一個,UIScrollView停留在後臺。有誰知道如何將UIScrollView帶回頂端?分層UIScrollView

下面是我的代碼,提前歡呼!

- (void)layerSelected:(id)sender 
{ 
int index = filterControl.selectedSegmentIndex; 

switch (index) 
{ 
    case 0: if (scroll == nil) 
      { 
       scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
       scroll.pagingEnabled = YES; 
       scroll.delaysContentTouches = NO; 
       scroll.userInteractionEnabled = YES; 
       NSInteger viewCount = 15; 
       for (int i = 0; i < viewCount; i++) 
       { 
        CGFloat yOrigin = i * self.view.frame.size.width; 
        UIImageView *filterViewOverlay = [[UIImageView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
        [filterViewOverlay setImage:[filterManager objectAtIndex:i]]; 
        [scroll addSubview:filterViewOverlay]; 
        [filterViewOverlay release]; 
       } 
       scroll.contentSize = CGSizeMake(self.view.frame.size.width * viewCount, self.view.frame.size.height); 
       [self.scroll setContentOffset:currentPos1]; 
       [self.view addSubview:scroll]; 
       [scroll release]; 
      } 
      else 
      { 
       [self.scroll setContentOffset:currentPos1]; 
       scroll.scrollEnabled = YES; 
      } 

      break; 

回答

0

如果兩個滾動視圖是主視圖的子視圖,那麼你需要調用[mainView bringSubviewToFront:scrollView];

+0

感謝,我現在遇到的問題是,在段1分段的控制加載,但不加載了滾動。爲了讓我加載段1 - 我必須加載段2,然後回到1 ...任何想法? – 2012-01-17 12:37:10