在缩放后由html脚本越野车填充的web视图上的对角线滑动

Ben*_*Ong 9 uiwebview uiscrollview ios swift

我有一个Web视图,显示比屏幕大得多的表.当我尝试在对焦后对角滚动 - 无论是向内还是向外,它通常只向单个方向滚动而不是对角滚动.这种行为是由于网页视图的滚动视图还是我的代码中出错?

这就是我填充网络视图的方式:

    webViewContent.scrollView.bounces = false
    webViewContent.scrollView.bouncesZoom = false
    webViewContent.scrollView.delegate = self
    webViewContent.scalesPageToFit = true

    var htmlString = "<html><head>... ... a really long string that creates a table"
    webViewContent.loadHTMLString(htmlString, baseURL: nil)
Run Code Online (Sandbox Code Playgroud)

请告诉我,如果htmlString可能会影响,我没有包含它,因为它真的很长.

我还尝试将视图与名为webViewTitle的标题行同步,我使用类似的代码填充,但只有一行.同步代码如下:

func scrollViewDidZoom(_ scrollView: UIScrollView) {
    if(scrollView != webViewTitle.scrollView){
        var zoomPadding:CGFloat = 0.0
        if((currentZoomScale*webViewContent.scrollView.zoomScale) < 1){
            zoomPadding = 0.5*(-acos(currentZoomScale*webViewContent.scrollView.zoomScale)*180.0/CGFloat.pi)
        }else{
            zoomPadding = 0.5*acos(2-(currentZoomScale*webViewContent.scrollView.zoomScale))*180.0/CGFloat.pi
        }
        webViewTitle.scrollView.zoom(to: CGRect(x: webViewContent.scrollView.contentOffset.x,
                                                y: (355*currentZoomScale*webViewContent.scrollView.zoomScale) + zoomPadding,
                                                width: webViewTitle.scrollView.bounds.width/currentZoomScale/webViewContent.scrollView.zoomScale,
                                                height: webViewTitle.scrollView.bounds.height/currentZoomScale/webViewContent.scrollView.zoomScale),
                                     animated: false)
    }
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
    var zoomPadding:CGFloat = 0.0
    if((currentZoomScale*webViewContent.scrollView.zoomScale) < 1){
        zoomPadding = 0.5*(-acos(currentZoomScale*webViewContent.scrollView.zoomScale)*180.0/CGFloat.pi)
    }else{
        zoomPadding = 0.5*acos(2-(currentZoomScale*webViewContent.scrollView.zoomScale))*180.0/CGFloat.pi
    }
    if(scrollView == webViewTitle.scrollView){
        webViewTitle.scrollView.contentOffset.y = (355*currentZoomScale*webViewContent.scrollView.zoomScale) + zoomPadding
        webViewContent.scrollView.contentOffset.x = webViewTitle.scrollView.contentOffset.x
    }else{
        webViewTitle.scrollView.contentOffset.y = (355*currentZoomScale*webViewContent.scrollView.zoomScale) + zoomPadding
        webViewTitle.scrollView.contentOffset.x = webViewContent.scrollView.contentOffset.x
    }
}
Run Code Online (Sandbox Code Playgroud)

这些中的任何一个都会导致对角线滚动变成马车吗?

BHe*_*cks -1

这些是否会导致对角滚动出现问题?

是的

从提供的代码中,您正在实现UIScrollViewDelegatefor UIWebView,但在两个显示的实现中,您没有调用super。这意味着scrollView不会有它的标准行为,而是严格使用您的代码来实现它的scrollViewDidScroll行为scrollViewDidZoom

虽然这个问题不一定能清楚地说明到底发生了什么,但我相信这与您面临的问题相同。

总之:至少,调用super的每个委托实现UIScrollViewDelegate,或者如果您不需要任何自定义滚动行为,则delegate完全删除。