Disable vertical scroll in UIScrollView Swift

前端 未结 8 1007
鱼传尺愫
鱼传尺愫 2021-02-15 00:47

(Don\'t mark this question as duplicated. I read a lot of questions but I don\'t find the answer to my issue.)

My issue is the following: I have a UIScrollView

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-15 01:08

    very charm solution is:

         // also don't forget
         // YourViewController: UIViewController, UIScrollViewDelegate {
    
      @IBOutlet weak var scrollView: UIScrollView!
    
      override func viewDidLoad() {
        super.viewDidLoad()
    
        self.scrollView.delegate = self
      }
    
      func scrollViewDidScroll(_ scrollView: UIScrollView) {
         if scrollView.contentOffset.y > 0 || scrollView.contentOffset.y < 0 {
            scrollView.contentOffset.y = 0
         }
      }
    

提交回复
热议问题