UIWebview 和 UIScrollview
我有一个 UIScrollview 来允许分页,还有一个 UIWebview 在内部的详细视图上。 我知道根据苹果类参考你不应该这样做,但我没有看到其他选择。
为了做出更好的响应和体验,我禁用了 Webview 的滚动,方法是:
[[[webView subviews] lastObject] setScrollEnabled:FALSE];
但现在我正在寻找一种解决方案,根据内容使 Webview 具有正确的大小。有没有一种简单的方法可以做到这一点,即 Web 视图的宽度保持不变,但在需要显示完整文章时高度会(自动)增长? 这将消除滚动问题,因为滚动视图将负责此场景中的所有滚动。
这有道理吗?
I have a UIScrollview to allow for pagination, and a UIWebview on the detail views inside.
I know you are not supposed to do that according to Apples Class Reference, but I don't see another option.
In order to make responses and experience a bit better, I disabled scrolling of the Webview, with:
[[[webView subviews] lastObject] setScrollEnabled:FALSE];
But now I am looking for a solution to make the webview the right size, depending on the content. Is there an easy way to do this, where the width of the webview stays the same, but the height grows (automatically) when that is required to show the full article?
This will remove the scrolling problem, as it sit he scrollview who will take care of all the scrolling in this scenario.
Does that make sense?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然 - 这并不是一种罕见的情况(需要计算出 UIWebView 的整个高度,以便您可以调整其框架的大小以避免 Web 视图本身滚动,例如当 Web 视图处于表视图或父滚动视图)。
你应该参考这个答案:
如何确定基于 UIWebView 的高度在内容上,在可变高度 UITableView 内?
这基本上会回答你的问题。您创建滚动视图,加载内容,运行一些 JavaScript 以获得完整高度,然后调整 Web 视图框架以反映内容的完整高度。
Sure - this isn't that uncommon a scenario (needing to figure out the entire height of a
UIWebView
so you can size it's frame to avoid the web view itself scrolling, such as when a web view is in a table view, or parent scroll view).You should refer to this answer:
How to determine UIWebView height based on content, within a variable height UITableView?
Which will basically answer your question. You create your scroll view, load in the content, run some javascript to get the full height, and then adjust the web view frame to reflect the full height of the content.