問題描述
我的 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模板網!