Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jeremyapp

macrumors newbie
Original poster
Apr 30, 2008
27
0
Hey,

I've been having some trouble with a UIScrollView in my project. Is there a way to track which "page" a UIScrollView is on? I have tried using an integer "currentPage" and incrementing it with delegate methods, but I haven't found this to be accurate (and nor does it allow for me to track when the user scrolls backwards).

I haven't been able to find a good way to do it yet. Anyone have a good way to do this?

Thanks!
 

jeremyapp

macrumors newbie
Original poster
Apr 30, 2008
27
0
Update: Never mind, I figured it out. For anyone who's interested, here's the code:

Code:
- (void)scrollViewDidScroll:(UIScrollView *)sender {
    CGFloat pageWidth = scrollView.frame.size.width;
    int currentPage = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
}

If anyone has a better way, let me know.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.