简体   繁体   English

如何提高[NSString drawInRect:withFont]的性能?

[英]How to improve the performance of [NSString drawInRect:withFont]?

I'm implementing an app for a micro blog service, something similar to twitter. 我正在为微博客服务实现一个应用程序,类似于Twitter。 I've done everything I know to improve the performance, including using drawRect instead of sub view based architecture. 我已经做了一切提高性能的事情,包括使用drawRect而不是基于子视图的体系结构。

After run the app with Instrument, I found that [NSString drawInRect:withFont] takes up more than 50% time, especially during the first time scrolling, after which I can scroll quite smoothly. 使用Instrument运行应用程序后,我发现[NSString drawInRect:withFont]占用了50%以上的时间,尤其是在第一次滚动时,此后我可以非常流畅地滚动。 Although [NSString drawInRect:withFont] still takes up the most of time, it's significantly smoother, and no obvious lag can be noticed. 尽管[NSString drawInRect:withFont]仍然占据大部分时间,但是它更加平滑,并且没有明显的滞后。

I don't know if the layers are cached or something, but with break point and NSLog I can see that drawRect and drawInRect are still called. 我不知道图层是否已缓存,但是有了断点和NSLog,我可以看到仍然调用drawRectdrawInRect Then why it only lags at the first time of scrolling? 那为什么只在第一次滚动时滞后呢?

The twitter's official app really has excellent performance. Twitter的官方应用程序确实具有出色的性能。 Is there any insider that can tell me some practical tricks? 有没有内部人士可以告诉我一些实用技巧?

Actually, Loren Bricher, the developer behind the Twitter app wrote a blog post about just this. 实际上,Twitter应用程序背后的开发人员Loren Bricher就此写了一篇博客文章。

You can check it out here: http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview 您可以在这里查看: http : //blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview

(Tweetie is the name of the official Twitter app before it was bought by Twitter, in case you didn't know.) (Tweetie是Twitter官方Twitter应用的名称,以防万一您不知道。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM