How to disable horizontal scrolling of UIScrollView?

前端 未结 14 1952
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 08:17

I have a UIView like iPhone\'s Springboard. I have created it using a UIScrollView and UIButtons. I want to disable horizontal scrolli

14条回答
  •  忘掉有多难
    2020-12-02 08:41

    In my case, with Swift 4.2 you can use:

    Disable vertical scroll:

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        scrollView.contentOffset.y = 0.0
    }
    

    Disable horizontal scroll:

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        scrollView.contentOffset.x = 0.0
    }
    

提交回复
热议问题