Scrolling a horizontal UIScrollView in stepped increments?

前端 未结 3 945
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 23:51

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

Is there a way to make the scrolling only move in stepped in

相关标签:
3条回答
  • 2021-01-04 23:52

    If you target iOS 5.0, you can use the new UIScrollViewDelegate method scrollViewWillEndDragging:withVelocity:targetContentOffset. This allows you to set the point where the scrolling animation will end after the user has stopped dragging the scroll view.

    0 讨论(0)
  • 2021-01-05 00:01

    Yup there is:

    yourScrollView.pagingEnabled = YES;
    

    Check the UIScrollView for more information.

    If the value of this property is YES, the scroll view stops on multiples of the scroll view’s bounds when the user scrolls. The default value is NO.

    I suggest you may need to change your view structure to something like this:

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

    Center the UIScrollView horizontally and make sure that the UIView that contains the UIScrollView has a width that is a multiple of the width of the UIScrollView

    0 讨论(0)
  • 2021-01-05 00:02

    While I think paging is probably the right answer, it's not what you were asking, which was jerky scrolling (columns "at all times"). I believe you could provide a -scrollViewDidScroll: delegate and adjust contentOffset to the nearest column.

    0 讨论(0)
提交回复
热议问题