How do I enable horizontal scrolling and disable vertical scrolling in 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 中启用水平滚动和禁用垂直滚动
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01