如何在UIScroll中获取当前的UIView?

时间:2012-06-20 18:29:27

标签: ios uiscrollview

目前,我有一个带有X UIView的UIScrollView作为页面。我想知道是否有办法获得UIView; s当前显示?

    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 吗?

1 个答案:

答案 0 :(得分:3)

我认为这应该有效:

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

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