gpt4 book ai didi

html - 有没有办法在 iOS 8 中加快 HTML 到 NSAttributedString 的渲染?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:16:14 26 4
gpt4 key购买 nike

我可能是错的,但它似乎比 iOS 7 慢很多。它在 iOS 8 的生产环境中几乎无法使用。

下面一行:

NSString *htmlString = @"<em>emphasis</em> with some <strong>bolder text</strong>";
[[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil];

执行需要 0.48 秒。半秒解析两个简单的 HTML 标签。

但我想知道是否有什么奇怪的事情发生,好像我使用了 HTML 字符串:

NSString *htmlString = @"<em>emphasis</em> with some <strong>bolder text</strong> and <a href='http://google.ca'>google</a> with some <sup>superscript</sup> and some <sub>subscript</sub> and a <h1>header</h1> followed by some <strong><em>nested bold and italics</em></strong> plus some <em>neato</em> and some more <a href='#'>well then</a> with a bit of <del>strikethrough</del> and other text <em>emphasis</em> with some <strong>bolder text</strong> and <a href='http://google.ca'>google</a> with some <sup>superscript</sup> and some <sub>subscript</sub> and a <h1>header</h1> followed by some <strong><em>nested bold and italics</em></strong> plus some <em>neato</em> and some more <a href='#'>well then</a> with a bit of <del>strikethrough</del> and other text <em>emphasis</em> with some <strong>bolder text</strong> and <a href='http://google.ca'>google</a> with some <sup>superscript</sup> and some <sub>subscript</sub> and a <h1>header</h1> followed by some <strong><em>nested bold and italics</em></strong> plus some <em>neato</em> and some more <a href='#'>well then</a> with a bit of <del>strikethrough</del> and other text <em>emphasis</em> with some <strong>bolder text</strong> and <a href='http://google.ca'>google</a> with some <sup>superscript</sup> and some <sub>subscript</sub> and a <h1>header</h1> followed by some <strong><em>nested bold and italics</em></strong> plus some <em>neato</em> and some more <a href='#'>well then</a> with a bit of <del>strikethrough</del> and other text <em>emphasis</em> with some <strong>bolder text</strong> and <a href='http://google.ca'>google</a> with some <sup>superscript</sup> and some <sub>subscript</sub> and a <h1>header</h1> followed by some <strong><em>nested bold and italics</em></strong> plus some <em>neato</em> and some more <a href='#'>well then</a> with a bit of <del>strikethrough</del> and other text";

这是一个 33x 长的 HTML 字符串,耗时 0.51 秒

所以字符串的长度是 33 倍,但渲染时间只需要 1.06 倍(或 0.03 秒)。

是否只有一个荒​​谬的启动时间我可以以某种方式减轻?这似乎花费了非常不合理的时间来渲染,而在 iOS 7 中我几乎记得它是瞬时的。

如果没有,是否有关于替代 HTML 到 NSAttributedString 解决方案的建议?

最佳答案

不幸的是,使用内置框架将文本从 HTML 转换为 NSAttributedText 的性能令人无法接受。您应该考虑使用 3rd 方库,例如 DCCoreText。

https://github.com/Cocoanetics/DTCoreText

关于html - 有没有办法在 iOS 8 中加快 HTML 到 NSAttributedString 的渲染?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28421816/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com