如何在 UIWebview 中启用水平滚动和禁用垂直滚动

How do I enable horizontal scrolling and disable vertical scrolling in UIWebview?(如何在 UIWebview 中启用水平滚动和禁用垂直滚动?)

本文介绍了如何在 UIWebview 中启用水平滚动和禁用垂直滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 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?

推荐答案

启用水平滚动和禁用垂直滚动:

myWebView.scrollView.delegate = self;
[myWebView.scrollView setShowsVerticalScrollIndicator:NO];

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.y > 0  ||  scrollView.contentOffset.y < 0 )
        scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, 0);
}

那里的第二行将隐藏垂直滚动指示器.检查scrollView.contentOffset.y < zero"是否会在您尝试向下滚动时禁用弹跳.你也可以这样做:scrollView.bounces=NO 做同样的事情!!通过查看 Rama Rao 的回答,我可以看出他的代码会在您尝试垂直滚动时将 scrollView 重置为 (0.0),从而将您从水平位置移开,这并不好.

the 2nd line there will hide the vertical scroll indicator. Checking if "scrollView.contentOffset.y < zero" will disable the bouncing when you attempt to scroll downwards. You can also do: scrollView.bounces=NO to do the same thing!! By just looking at Rama Rao's answer i can tell that his code will reset the scrollView to (0.0) the moment you try to scroll vertically, thereby moving you away from your horizontal position, which is not good.

启用垂直滚动并禁用水平滚动:

myWebView.scrollView.delegate = self;
[myWebview.scrollView setShowsHorizontalScrollIndicator:NO];

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.x > 0)
        scrollView.contentOffset = CGPointMake(0, scrollView.contentOffset.y);
}

和平

这篇关于如何在 UIWebview 中启用水平滚动和禁用垂直滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 UIWebview 中启用水平滚动和禁用垂直滚动

基础教程推荐