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

后端 未结 4 452
走了就别回头了
走了就别回头了 2020-12-31 13:13

My UIWebView should not allow vertical scrolling. However, horizontal scrolling should possible.

I have been looking through the documentation, but couldn\'t find an

4条回答
  •  -上瘾入骨i
    2020-12-31 14:05

    To make it full work, write:

     webview.scrollView.delegate = self;
        [webview.scrollView setShowsHorizontalScrollIndicator:NO];
    
    }
    
    -(void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        if (scrollView.contentOffset.x > 0)
            scrollView.contentOffset = CGPointMake(0, scrollView.contentOffset.y);
        if (scrollView.contentOffset.x < 0)
            scrollView.contentOffset = CGPointMake(0, scrollView.contentOffset.y);
    }
    

    I have just added the last two lines, because when you write it like pnizzle did, you can't scroll from the right to the left side, but still from the left to the right.

    Good luck

提交回复
热议问题