UIScrollView disable scrolling in just one direction?

前端 未结 10 1827
暗喜
暗喜 2020-12-13 09:40

I\'ve been unable to find an answer for this (maybe someone has hacked a solution together).

Is it possible to disable scrolling in a UIScrollView in one direction?

10条回答
  •  我在风中等你
    2020-12-13 10:20

    Instead of using a UIScrollViewDelegate to correct the already wrong contentOffset (which will result in a jittery behaviour) you may want to consider to sub class UIScrollView instead and overriding setContentOffset:

    - (void)setContentOffset:(CGPoint)contentOffset {
        if (contentOffset.y <= 60) {
            [super setContentOffset:contentOffset];
        }
    }
    

    Off course this can be generalized by adding a property for the min or max allowed value for the content offset. You may need to override setContentOffset:animated: as well.

提交回复
热议问题