我的 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 中启用水平滚动和禁用垂直滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在 swift 3.0 中设置滚动视图内容大小how to set scrollview content size in swift 3.0(如何在 swift 3.0 中设置滚动视图内容大小)
阻止 UITableView 自动滚动Stop a UITableView from automatically scrolling(阻止 UITableView 自动滚动)
iOS UIScrollView 延迟加载iOS UIScrollView Lazy Loading(iOS UIScrollView 延迟加载)
在 iOS 5 模拟器上运行时,使用 iOS 6.0 SDK 并为 iusing iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模拟器上运
以编程方式创建部分屏幕 UIPageViewControllerCreate partial-screen UIPageViewController programmatically(以编程方式创建部分屏幕 UIPageViewController)
如何使用或不使用 ScrollView 使 ImageView 可缩放?how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可缩放?)