Reputation: 2275
I'm trying to get the scroll position from a webview in swift. I want to obtain the position when scrolling. Everytime I start scrolling I would like to get the position of the current scroll and the height of the total scroll. How can this be accomplished?
Upvotes: 1
Views: 5264
Reputation: 1298
try this,
ScrollView contentOffset
defines the point of origin of the content view
let x_OffsetValue = webView.scrollView.contentOffset.x
let y_OffsetValue = webView.scrollView.contentOffset.y
Upvotes: 1
Reputation: 5451
The scroll view associated with the WKWebView
and
UIWebView
you can get webView total scroll contentSize
as follow
webView.scrollView.contentSize
current scroll position
webView.scrollView.contentOffset
Upvotes: 1
Reputation: 764
Try this, you can get scroll position of UIWebview:
func scrollViewDidScroll(scrollView: UIScrollView) {
if scrollView.contentSize.height - scrollView.contentOffset.y - scrollView.frame.size.height < 120 {
print("the end")
} else if scrollView.contentOffset.y < 120 {
print("the beginning")
}
}
Upvotes: 0