UIWebView 性能与具有许多标签的 UIScrollView 相比

发布于 2024-10-09 07:56:47 字数 367 浏览 0 评论 0原文

在 iOS 应用程序中,我必须显示以字符串形式存储在数组中的文本项列表。由于文本行的格式不同(大小、颜色),我尝试了两种不同的方法:

  1. 创建 UIWebView,在运行时根据数组中的字符串创建 htmlstring,并使用加载的 css 文件对其进行格式化

  2. 创建一个 UIScrollView,并为每个字符串创建一个 UILabel 并在后面添加一个带有虚线图像的 UIImageView每个标签(我在上面的方法中使用CSS完成)

我预计第二种方法的性能会很差。但看起来带有标签(约 100)的滚动视图和图像滚动更平滑并且比网络视图响应更快。

怎么可能呢?我在后台什么也不做,只是显示这个视图。多谢!

in an iOS app I have to display a list of text items that are stored as strings in an array. Since the lines of text would be formatted differently (size, color), I tried two different approaches:

  1. create an UIWebView, make a htmlstring at runtime from the strings in the array and format it with a loaded css file

  2. create an UIScrollView, and create an UILabel for every string AND add an UIImageView with an image of a dotted line after each label (which I do with css in the approach above)

I expected very poor performance from the second approach. BUT it seems the scrollview with the labels (ca. 100) an images scrolls smoother and is more responsive than the webview.

How could that be? I do nothing in the background, just display this view. Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘逸的'云 2024-10-16 07:56:47

如果我没记错的话,这是因为 UIWebView 没有预渲染任何内容。

含义 - UIScrollView 缓存所有数据以实现平滑过渡,而 UIWebView 在进入视图时渲染它。

If I'm not mistaken it's because UIWebView doesn't pre-render anything.

Meaning - UIScrollView caches all your data for smooth transition while UIWebView renders it as it enter the view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文