Disable vertical scroll in UIScrollView Swift

前端 未结 8 2117
情深已故
情深已故 2021-02-15 00:37

(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 00:56

    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
         }
      }
    

提交回复
热议问题