需求1:我们在最下方有一个按钮 网页向上滚动的时候:消失 向下滚动的时候: 出现
func scrollViewDidScroll(_ scrollView: UIScrollView) {
newContentOffsetY = scrollView.contentOffset.y
if (newContentOffsetY > oldContentOffsetY) && (oldContentOffsetY > contentOffsetY) {
returnView.alpha = 0
self.rightUpdateBtn?.isHidden = true
}else if (newContentOffsetY < oldContentOffsetY) && (oldContentOffsetY < contentOffsetY){
if newContentOffsetY < ScreenHeight*1.5 {
returnView.alpha = 0
}else{
returnView.alpha = 1
}
self.rightUpdateBtn?.isHidden = false
}
if (scrollView.contentOffset.y + scrollView.height + 15) > scrollView.contentSize.height {
returnView.alpha = 1
self.rightUpdateBtn?.isHidden = false
}
}
需求2: 控制网页的点击 控制跳转方向
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void){
let tmpStr = navigationAction.request.url?.absoluteString
// print("点击的事件拦截: \(navigationAction.request.url?.absoluteString)")
if (tmpStr?.contains(agodaDownStr ?? "")) ?? false {
decisionHandler(WKNavigationActionPolicy.cancel)
SVProgressHUD.show(nil, status: "咱不支持跳转app")
}else{
decisionHandler(WKNavigationActionPolicy.allow)
}
}
网友评论