Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable horizontal scrolling and disable vertical scrolling in UIWebview?

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?

like image 620
bitmapdata.com Avatar asked Apr 11 '12 02:04

bitmapdata.com


1 Answers

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)
    }
}
like image 94
mehdigriche Avatar answered Nov 15 '22 11:11

mehdigriche