2011-12-22 87 views
0

尋找最佳方法: 我有一個tabbar和一個導航欄。在導航欄下方,我放了三個按鈕。 一個用於項目描述,下一個應該顯示項目時間表和第三個項目任務。 在按鈕下方,我有一個內容滾動視圖。 根據使用哪個按鈕,切換/更改滾動視圖內容的最佳方式是什麼?更改UIScrollView中的內容

回答

0

我會構建3個不同的視圖,當按鈕點擊清除滾動視圖,然後將新視圖添加到滾動視圖,然後調整滾動視圖的內容大小。

0

UITextView是UIScrollView的子類,因此自動實現滾動行爲。您可以使用text屬性來設置顯示的文本。

如果您要顯示的不僅是文本,您可以通過編程方式(或通過從NIB加載它)創建自定義視圖,並在單擊按鈕時將其放入UIScrollView。

0

您可以使用scrollRectToVisible,像這樣:

-(void)scrollToIndex(UIButton*)sender{ 

    UIButton *btn = (UIButton*)sender; 
    NSInteger *index = btn.tag; 
    CGRect rect = CGRectMake(CGRectGetWidth(self.contentScrollView.frame)*index, 0, CGRectGetWidth(self.contentScrollView.frame), CGRectGetHeight(self.contentScrollView.frame)); 
    [self.contentScrollView scrollRectToVisible:rect animated:YES]; 

}  

}

現在,它的操作系統很好的,如果用戶想手動滾動視圖來處理其他選項:

- (void)scrollViewDidScroll:(UIScrollView *)sender { 
    // Switch the currentDataView when more than 50% of the previous/next page is visible 
    CGFloat pageWidth = sender.frame.size.width; 
    int page = floor((sender.contentOffset.x - pageWidth/2)/pageWidth) + 1; 
    pageControl.currentPage = page; 

    //You can also set the highlight of the button that relate to this view 
}