views:

66

answers:

3

I have a UIScrollView in a UIViewController view that scrolls horizontally. How can I detect whether the scroll is at the left end or right end or somewhere in the middle?

A: 

cant you check contentOffset and compare it to contentSize?

GameBit
A: 

GameBit is correct here, but to elaborate -

The UIScrollView has a member variable contentOffset, that describes how many pixels from the origin the scrollview has scrolled. A positive value is a scroll to the right, negative is a scroll to the left.

Is your UIScrollView in Paged mode? if so this will help:

 CGFloat pageWidth = scrollView.frame.size.width;
    int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
fogelbaby
A: 

Hi Ive tried getting scrollView.contentOffset.x in scrollViewDidScroll: . but it always returns 0. and no my UIscrollview is not in paged mode

Rupert
sorry my bad i was NSloging an in for xontentOffset.x
Rupert