Scrolling horizontal UIScrollView in increments?

I have a UIScrollView that can be scrolled horizontally. Scrolling content is displayed in columns.

Is there a way to scroll only step by step, instead of pixels (i.e. move columns at a time).

Diagram: enter image description here

+8
ios objective-c cocoa-touch ios5 uiscrollview
source share
3 answers

Yup is:

yourScrollView.pagingEnabled = YES; 

See UIScrollView for more details.

If the value of this property is YES, the scroll view stops at multiple scroll boundaries when the user scrolls. The default value is NO.

I suggest you change the view structure to something like this:

 +--------+ | | <- UIView to hold your structure +--------+ +--+ | | <- UIScrollView, clipsToBounds = NO, width = column.width +--+ +--+--+--+ | | | | <- UIView columns +--+--+--+ 

Center the UIScrollView horizontally and verify that the UIView containing the UIScrollView is a multiple of the width of the UIScrollView

+7
source share

While I think the search call is probably the right answer, this is not what you asked for, it was a disgusting scroll (always columns). I believe that you could provide the delegate -scrollViewDidScroll: and set the contentOffset to the nearest column.

+1
source share

If you are targeting iOS 5.0, you can use the new UIScrollViewDelegate scrollViewWillEndDragging: withVelocity: targetContentOffset method. This allows you to set the point at which the animation scroll ends after the user has stopped dragging the scroll.

+1
source share

All Articles