如何在UIWebview中启用水平滚动并禁用垂直滚动? [英] How do I enable horizontal scrolling and disable vertical scrolling in UIWebview?

查看:98
本文介绍了如何在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;

如何解决这个问题?

推荐答案

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

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中启用水平滚动并禁用垂直滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆