UIWebView怎么禁止水平方向滚动
答案:1 悬赏:40 手机版
解决时间 2021-11-12 11:38
- 提问者网友:世勋超人
- 2021-11-11 10:58
UIWebView怎么禁止水平方向滚动
最佳答案
- 五星知识达人网友:空山清雨
- 2021-11-11 12:13
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);
}
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);
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯