Reputation: 1614
Currently, I have a UIScrollView with X UIView as pages. I would like to know is there is way to get the UIView that;s is currently displayed?
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;
There any way to get the awesomeView currently displayed?
Upvotes: 1
Views: 1115
Reputation: 4085
I think this should work:
int pageIndex = mScroll.contentOffset.x/awesomeView.frame.size.width;
Just add these views to an array to access them or set their tag to 0,1,2
Upvotes: 3