Detect when I scroll my UIWebView at top of the page

后端 未结 3 2031
萌比男神i
萌比男神i 2021-01-15 11:33

I would like to add an URL/google bar on top of my webview, and access it by scrolling up my web page exactly as Safari do. To do this, I would detect when the user is scrol

3条回答
  •  迷失自我
    2021-01-15 12:17

    You can use the following methods to solve your problem.

    For getting the pageOffset:

    int pageYOffset = [[webViewObj stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];

    For getting the total scroll height of a webpage:

    int scrollHeight = [[webViewObj stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] intValue];

    For scrolling the webpage to a particular offset:

    [webViewObj stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.scrollTop = %d",scrollHeight ]];

提交回复
热议问题