首页 > 代码库 > UIWebview 禁止某个方向滚动
UIWebview 禁止某个方向滚动
Enable Horizontal scrolling and disable Vertical scrolling:
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);}
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.
Enable vertical scrolling and disable Horizontal scrolling:
myWebView.scrollView.delegate = self;[myWebview.scrollView setShowsHorizontalScrollIndicator:NO];-(void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (scrollView.contentOffset.x > 0) scrollView.contentOffset = CGPointMake(0, scrollView.contentOffset.y);}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。