(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
You can simply do this. Swift 4
self.scrollView.contentSize.height = 1.0 // disable vertical scroll
just set the contentOffset in scrollViewDidScroll
if scrollView.contentOffset.y > 0 {
scrollView.contentOffset = CGPoint(x: scrollView.contentOffset.x, y: 0)
}
Swift 5
scrollView.isScrollEnabled = false
In swift
self.scrollView.contentSize.width = 1.0 // disable vertical scroll
Since iOS 11 content insets can get adjusted automatically. Try setting your scrollview's behaviour to not adjust it.
if #available(iOS 11, *) {
scrollview.contentInsetAdjustmentBehavior = .never
}
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
}
}