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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Cancel current UIScrollView touch(取消当前 UIScrollView 触摸)
Scale image to fit screen on iPhone rotation(缩放图像以适应 iPhone 旋转时的屏幕)
How to make a screenshot of all the content of a Scrollview?(如何截取 Scrollview 的所有内容?)
Swift iOS Set scrollView constraint below navigation bar programmatically(Swift iOS以编程方式在导航栏下方设置滚动视图约束)
UILabel sizeToFit method not working properly(UILabel sizeToFit 方法无法正常工作)
Get the current UIScrollView scroll values on the iPhone?(获取 iPhone 上当前的 UIScrollView 滚动值?)