How to Stop UIWebView from “bouncing” vertically scrolling bottom?

一个人想着一个人 提交于 2019-12-12 02:49:13

问题


My question is the same as this question, but has one difference. When I scroll to top refresh my website, I want stop bouncing only to the end of the bottom scroll. How do I do this?


回答1:


You can try like this :

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)
    }   
}

Set the delegate of your webview and set the content offset of the webview's scrollview

Ref taken from: https://stackoverflow.com/a/14084747/4557505




回答2:


Personally in Xcode 7.3 in Swift, I Simply add this in the viewDidLoad Function:

UIWebview.scrollView.bounces = false;



回答3:


I think you can also set the scrollview's bounces

like this,It's simple

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.contentOffset.y > 0) {
        scrollView.bounces = NO;
    }else{
        scrollView.bounces = YES;
    }
}


来源:https://stackoverflow.com/questions/36407633/how-to-stop-uiwebview-from-bouncing-vertically-scrolling-bottom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!