如何阻止 UIWebView 垂直滚动底部“弹跳”?
How to Stop UIWebView from “bouncing” vertically scrolling bottom?
我的问题与this question相同,但有一处不同。当我滚动到顶部刷新我的网站时,我只想停止弹跳到底部滚动的末尾。我该怎么做?
你可以这样试试:
override func viewDidLoad() {
super.viewDidLoad()
webview.scrollView.delegate = self
}
func scrollViewDidScroll(scrollView: UIScrollView) {
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
scrollView.setContentOffset(CGPointMake(scrollView.contentOffset.x, scrollView.contentSize.height - scrollView.frame.size.height), animated: false)
}
}
设置你的webview的delegate并设置webview的scrollview的content offset
引用自:
我想你也可以设置滚动视图的反弹
像这样,很简单
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.contentOffset.y > 0) {
scrollView.bounces = NO;
}else{
scrollView.bounces = YES;
}
}
个人在Xcode7.3中Swift,我在viewDidLoad函数中简单的添加了这个:
UIWebview.scrollView.bounces = false;
我的问题与this question相同,但有一处不同。当我滚动到顶部刷新我的网站时,我只想停止弹跳到底部滚动的末尾。我该怎么做?
你可以这样试试:
override func viewDidLoad() {
super.viewDidLoad()
webview.scrollView.delegate = self
}
func scrollViewDidScroll(scrollView: UIScrollView) {
if (scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height) {
scrollView.setContentOffset(CGPointMake(scrollView.contentOffset.x, scrollView.contentSize.height - scrollView.frame.size.height), animated: false)
}
}
设置你的webview的delegate并设置webview的scrollview的content offset
引用自:
我想你也可以设置滚动视图的反弹
像这样,很简单
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.contentOffset.y > 0) {
scrollView.bounces = NO;
}else{
scrollView.bounces = YES;
}
}
个人在Xcode7.3中Swift,我在viewDidLoad函数中简单的添加了这个:
UIWebview.scrollView.bounces = false;