iOS 6 UIWebView状态恢复如何工作? [英] How does iOS 6 UIWebView state restoration work?

查看:113
本文介绍了iOS 6 UIWebView状态恢复如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档


在iOS 6及更高版本中,如果为此视图的restorationIdentifier属性分配值,它会尝试保留其URL历史记录,每个属性的缩放和滚动位置页面,以及有关当前正在查看哪个页面的信息。在恢复期间,视图会恢复这些值,以便网络内容像以前一样显示。

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.

我正在做所有这些,但什么都没发生。即使我手动保存并恢复用户之前查看的URL,也不会恢复滚动位置。这些文档是错的吗?

I'm doing all that, but nothing is happening. And even if I manually save and restore the URL the user was looking at previously, the scroll position is not restored. Are the docs just wrong?

推荐答案

我已经尝试过Matt的答案并且效果很好,但是如果有转发页面的话历史堆栈 - 它们将被Web视图对象中的已恢复请求替换。

I have tried Matt's answer and it works well, however if there are 'forward' pages in the history stack-they will be replaced by the restored request within the web view object.

更好的方法是在webview对象上调用'reload'方法,这将恢复两个方向的历史记录以及缩放和内容滚动偏移。

A better approach is to instead call the 'reload' method on the webview object, this will restore the history in both directions as well as the zoom and content scroll offset.

如果你想要一个我的方法的例子或者你自己的更多功能webview,看看我的SVWebViewController的开源分支这里。

If you'd like an example of my approach or some more functionality for your own webview, take a look at my open source fork of SVWebViewController here.

这篇关于iOS 6 UIWebView状态恢复如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆