UIWebView 性能与具有许多标签的 UIScrollView 相比
在 iOS 应用程序中,我必须显示以字符串形式存储在数组中的文本项列表。由于文本行的格式不同(大小、颜色),我尝试了两种不同的方法:
创建 UIWebView,在运行时根据数组中的字符串创建 htmlstring,并使用加载的 css 文件对其进行格式化
创建一个 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:
create an UIWebView, make a htmlstring at runtime from the strings in the array and format it with a loaded css file
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我没记错的话,这是因为 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.