我可能是错的,但它似乎很多慢于它在iOS的7这一切都无法使用,但在生产与iOS 8有没有办法在iOS 8中加速HTML到NSAttributedString的渲染?
以下行:
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";
这是一个HTML字符串33X长,它需要0.51秒。
因此字符串是33X长,但需要较长的时间只有1.06倍(即0.03秒的时间)来渲染。
仅仅是一个荒谬的启动时间,我可以减轻不知何故?这看起来好像渲染时间非常不合理,而在iOS 7中,我几乎可以记住它是瞬时的。
如果没有,对NSAttributedString解决方案的替代HTML的任何建议?
目前还不清楚我从文档:'的HTML进口商不应该从后台线程调用(也就是选择字典包括NSDocumentTypeDocumentAttribute与NSHTMLTextDocumentType值).'是否指定这些字典中的值把它放在后台线程或主线程上? – 2015-02-10 00:11:53