javascript - 在 UIWebView 中恢复位置

标签 javascript ios iphone uiwebview state-restoration

我需要将 UIWebView 中的当前位置存储到磁盘并在稍后启动时从磁盘重新加载它。

我之前所做的是将window.scrollXwindow.scrollY 存储在javascript 位置。 这适用于许多情况。

此外,我通过获取电流来存储比例:

webView.scrollView.zoomScale

并通过使用 javascript 将视口(viewport)初始比例设置为它来恢复它。

所有这些都有效,但并不可靠。有没有更好的方法?

我阅读了关于 UIWebViewrestorationIdentifier 但我不确定是否可以将它保存到磁盘?

最佳答案

In iOS 6 and later, if you assign a value to this view’s restorationIdentifier property, it attempts to preserve its URL history, the scaling and scrolling positions for each page, and information about which page is currently being viewed. During restoration, the view restores these values so that the web content appears just as it did before.

更多来自 Apple Programming Guide和一个 tutorial以及示例项目。您可以运行它并将应用程序发送到后台,然后停止使用 Xcode 运行它,下次打开应用程序时,它会将其状态恢复到应用程序进入后台之前的状态。示例项目可以有一个小修复,在 viewDidAppear 中,如果 self.restoringStateNO,则调用 showPage功能。

关于javascript - 在 UIWebView 中恢复位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26920561/

相关文章:

javascript - 在指令模板中时,如何使 Angular ui-router ui-sref 工作?

javascript - 如何将 60 个相似的 jquery 函数组合成一个函数?

ios - 有没有比删除目录更快/更好的方法来清除 iPhone 模拟器缓存?

ios - 如何获取iPhone网络的信号强度(RSRP/RSSI/RSRQ/SINR),小区ID(LTE/3G/2G)

javascript - SweetAlert 输入验证

javascript - 如何从 python Flask 接收变量到 JavaScript?

ios - Swift AV Player 视频应该是 AspectFill 或全屏

ios - 禁用 uicollectionview 水平滚动的外部平移手势

ios - 锁定 UIScrollView 从右向左滚动

ios - dealloc 总是被调用吗?即使您滑动关闭应用程序?