0
我有一個PDF集合,有些是一個頁面,有些是兩個。我希望看到PDF的下一個可見屏幕高度值,或者如果PDF的剩餘高度小於webView的高度,請滾動到PDF的底部。到目前爲止,我只能讓webView滾動到底部。這是我的功能...我錯過了什麼?如何使用WKWebView(Swift)以PDF格式一次滾動一個視圖的高度(不是頁面)
func scrollDown() {
let scrollView = webview.scrollView
let contentSize = scrollView.contentSize
let contentOffset = scrollView.contentOffset
let frameSize = webview.frame.size
if scrollView.contentOffset.y <= 0 {
// Scroll one view's height at a time
// If the contentSize - offset.y is greater than the frame's height
if (contentSize.height - contentOffset.y) > frameSize.height {
scrollView.setContentOffset(CGPoint(x: 0, y: contentOffset.y + (contentSize.height - frameSize.height)), animated: true)
} else {
scrollView.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
}
}
}