Disabling vertical scrolling in UIScrollView

后端 未结 12 1991
终归单人心
终归单人心 2020-11-30 20:02

There is an option in IB to uncheck vertical scrolling on a scrollview, but it doesnt seem to work.

How can the scrollview be set to only scroll horizontally, and no

12条回答
  •  日久生厌
    2020-11-30 20:57

    The most obvious solution is to forbid y-coordinate changes in your subclass.

    override var contentOffset: CGPoint {
      get {
        return super.contentOffset
      }
      set {
        super.contentOffset = CGPoint(x: newValue.x, y: 0)
      }
    }
    

    This is the only suitable solution in situations when:

    1. You are not allowed or just don't want to use delegate.
    2. Your content height is larger than container height

提交回复
热议问题