0

I have a UIScrollView with ten UIViews in it and paging enabled. On scrollViewDidEndDecelerating: I want to decide which of the child UIViews is being displayed in the scroll view's frame.

I was going to check the top-left and bottom-right of each view to make sure that both points are in the scroll view's frame, but that seems like a less-efficient way.

Is there a better way to accomplish that?

jscs
  • 63,694
  • 13
  • 151
  • 195
Jacksonkr
  • 31,583
  • 39
  • 180
  • 284
  • check http://stackoverflow.com/questions/868288/getting-the-visible-rect-of-an-uiscrollviews-content – janusfidel Mar 16 '12 at 14:44
  • @janusfidel That is certainly a helpful first step. Thank You. – Jacksonkr Mar 16 '12 at 15:09
  • Why would you want to do that? If you have enabled paging in scroll view, the maximum visible view will be automatically adjusted to full view. – cocoakomali Mar 17 '12 at 10:30
  • @cocoakomali I want to change another part of the application depending on which view they switch to, but I need to know the active view before I can do that. – Jacksonkr Mar 17 '12 at 15:46
  • In order to do that, you can take the scroll view's content offset after scrolling and calculate it's position. I will give sample code as an answer. – cocoakomali Mar 17 '12 at 17:18

1 Answers1

0

The below code is from an assumption that it's an iphone app in portrait orientation.

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
     int page= floor((scrollView.contentOffset.x - 320/2) / 320)+1  ;
}
cocoakomali
  • 1,346
  • 1
  • 8
  • 7