My UIWebView should not allow vertical scrolling. However, horizontal scrolling should possible.
I have been looking through the documentation, but couldn't find any hints.
The following code disables both scrolling directions, but I want to only disable vertical:
myWebView.scrollView.scrollEnabled = NO;
How do I solve this problem?
Swift 4.2 :
Enable Horizontal scrolling and disable Vertical scrolling:
webview.scrollView.delegate = self
webView.scrollView.showsHorizontalScrollIndicator = false
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y > 0 || scrollView.contentOffset.y < 0{
scrollView.contentOffset = CGPoint(x: scrollView.contentOffset.x, y:0)
}
}
Enable vertical scrolling and disable Horizontal scrolling:
webview.scrollView.delegate = self
webView.scrollView.showsHorizontalScrollIndicator = false
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.contentOffset.x > 0 {
scrollView.contentOffset = CGPoint(x: 0, y:scrollView.contentOffset.y)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With