2012-06-20 75 views
1

目前,我有一個UIScrollView與X UIView作爲頁面。我想知道是否有方法可以獲得UIView; s當前顯示?如何獲取UIScroll中的當前UIView?

mScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
    mScroll.pagingEnabled = YES; 
    NSInteger numberOfViews = 3; 
    for (int i = 0; i < numberOfViews; i++) { 
     CGFloat yOrigin = i * self.view.frame.size.width; 
     MyICalView* awesomeView=[[MyICalView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
     [mScroll addSubview:awesomeView]; 
     [awesomeView release]; 
    } 
    mScroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height); 
    mScroll.delegate=self; 

有什麼辦法可以讓awesomeView當前顯示的?

回答

3

我認爲這應該工作:

int pageIndex = mScroll.contentOffset.x/awesomeView.frame.size.width; 

就這些意見添加到一個數組訪問他們或他們的標籤設置爲0,1,2