1

目前,我有一个带有 X UIView 作为页面的 UIScrollView。我想知道是否有办法获取当前显示的 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

4

1 回答 1

3

我认为这应该有效:

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

只需将这些视图添加到数组中即可访问它们或将它们的标记设置为 0,1,2

于 2012-06-20T18:35:14.737 回答