【发布时间】:2017-04-26 08:08:29
【问题描述】:
在我的 ios 应用程序中,我使用 WKWebview.evaluateJavaScript() 来执行 javascript 以获取 div boundingRect。在我的网页中,我使用 anjularjs 来渲染我的部分页面,页面内容如下,
<body ng-app="home" ng-controller="HomeController" style="min-height:700px;">
<printerinfo></printerinfo>
</body>
<div id="movie" style="border: 1px grey dotted; width: 120px; height: 90px;"></div>
迅速
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.wk.evaluateJavaScript("var rect = document.getElementById('movie').getBoundingClientRect(); [rect.x, rect.y, rect.width, rect.height, rect.top, rect.right, rect.bottom, rect.left];") { (result, error) -> Void in
print(result)
}
}
从结果来看,
Optional(<__NSArrayM 0x170251010>(
<null>,
<null>,
120,
90,
0,
120,
90,
0
)
)
boundingRect 位于视口的原点,看起来 body 在视口中没有空间。我以为是因为网页加载的时候,angualrjs没有渲染body部分。
那么如何在 anjularjs 用 swift3 渲染页面后执行 javascript 呢?
非常感谢。
【问题讨论】:
标签: ios angularjs swift3 synchronization wkwebview