2013-03-12 108 views
1

我遇到了一個問題,我有一個uiview在底部,我需要添加一些標籤,我想保持靜態。然後,我在uiview的頂部添加一些可滾動內容的滾動視圖。最後,我將原始uiview設置爲表頭headerView。即使正確的contentSize,scrollView也不會滾動。UIScrollView裏面UIView設置爲tableHeaderView不滾動

UIView *header=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 100*objects.count, 150)]; 
     [header setBackgroundColor:[UIColor redColor]]; 

    //set up scroll view 
    UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, 100*objects.count, 110)]; 
    scrollView.delegate=self; 
    scrollView.contentSize=CGSizeMake(100*objects.count, scrollView.frame.size.height); 
    [scrollView setUserInteractionEnabled:YES]; 
    [scrollView setScrollEnabled:YES]; 

    [header addSubview:scrollView]; 

    [scrollView setShowsHorizontalScrollIndicator:YES]; 
    [self.tableView setTableHeaderView:header]; 

    //add stuff to scroll view 

然而,當我只設置滾動視圖作爲tableHeaderView,滾動完美的作品

[self.tableView setTableHeaderView:scrollView]; 

任何人都可以建議我怎麼可以設置原來鈕的UIView作爲標題視圖,並有滾動視圖仍然工作?

+0

你能後的截圖,所以我們可以得到更好的主意嗎? – 2013-03-12 15:56:40

+0

除了滾動視圖沒有滾動 – Live2Enjoy7 2013-03-12 16:58:51

+0

可能是一個邊界問題沒有真正看到。 – Avigit 2013-03-12 17:14:56

回答

1

解決方案是使用scrollViewDidScroll委託方法滾動視圖並調整滾動量的內容偏移量。有點哈克,仍然不知道爲什麼這個scrollview問題正在發生,但它現在工作。

看起來像

-(void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 

    [self.featuredLabel setFrame:CGRectMake(5+scrollView.contentOffset.x, 5, self.view.frame.size.width, 18)]; 
    [self.recentLabel setFrame:CGRectMake(5+scrollView.contentOffset.x, 100, self.view.frame.size.width, 18)]; 

} 

找不到提到所謂後

相關問題