Fast Scrolling in Tweetie with UITableView
来源:互联网 发布:如何制作软件app 编辑:程序博客网 时间:2024/04/29 00:14
http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/
Fast Scrolling in Tweetie with UITableView
December 12, 2008
Scrolling is the primary method of interaction on the iPhone. It has to be fast. It has to be fast. More than a few developers have asked me how I do it in Tweetie, so I figured I would share a really fast and really clean technique people can adopt in their own apps.
The Solution
Cutting to the chase, here’s the secret: One custom view per table cell, and do your own drawing. Sounds simple? That’s because it is. It’s actually simpler than dealing with a ton of subviews of labels and images, and it’s about a bzillion times faster (according to my informal tests).
Why it’s Fast
Much like on Mac OS X, there are two drawing systems on the iPhone. One is CoreGraphics, the other is LayerKit CoreAnimation. CoreGraphics does drawing on the CPU, CoreAnimation does drawing on whatever it thinks is fastest - most likely the GPU.
The GPU on the iPhone hates blending, that’s why Apple recommends that you keep as many of your views opaque as possible. Sometimes you have no choice - if you have a label over an image you are forced to make the label transparent otherwise you get a big ugly block around your text.
What’s a developer to do? Pre-blend of course… with CoreGraphics into your own view. If you blend your stuff together into a single static view on demand (e.g. when a table view moves a cell onscreen), it’s a little bit more expensive for the first frame, but every frame after that CoreAnimation is just dealing with one big, opaque texture… which it loves. It’s more than just the blending too. If you think about what is happening in terms of overdraw, having one big view per table cell is a big win because CoreAnimation will only touch a single given pixel on the screen once rather than multiple times (potentially, depending on how much overlap your old view hierarchy had).
The Code
I put together a small example project showing off this technique. It’s a simple scrolling list of cells with some text but draws the text using two different fonts, much like the Address Book Contacts list on the iPhone (regular and bold fonts). The technique is extensible to pretty much any style cell you need - I use the same thing in Tweetie and draw the chat bubble, text, and avatar all together into a single view.
There is one handy class that you can use for everything, see: ABTableViewCell.h and ABTableViewCell.m in the full example project here: FastScrolling.zip.
It doesn’t help that Apple doesn’t have any good examples on how to get good scrolling performance. The one table view example I checked (a while ago, it may have been updated) was absolutely horrible in terms of scrolling performance. Horrible.
If you wanted to know why Tweetie is so fast, now you do. It’s an incredibly simple technique and should be very easy to adopt.
Update: It looks like Apple has in fact updated the example code. Check out the fifth example in their TableViewSuite.
- Fast Scrolling in Tweetie with UITableView
- How to implement scrolling image with javascript in web page
- Displaying Bitmap with Scrolling
- Displaying Bitmap with Scrolling
- Displaying Bitmap with Scrolling
- Scrolling with the Mouse
- Fast Updates with MongoDB (update-in-place)
- Scrolling CCNode in Cocos2d
- Smooth scrolling in Android
- fix screen scrolling in ubuntu xterm when used with GNU screen
- Working with multiple data-sources in UITableView
- Fast, Scalable Networking in Go with Mangos-nanomsg in go
- Scrolling a UITableView When Displaying the Keyboard
- Scrolling a UITableView When Displaying the Keyboard
- Perfect smooth scrolling in UITableViews
- Perfect smooth scrolling in UITableViews
- Fast Pixel Operations in .NET (With and Without unsafe)
- Scrolling and zooming chart with ChartScroller
- MongoDB Monitoring: Keep in it RAM
- 好的blog阅读习惯-读后感
- Google三篇不错的中文版本
- uidl.txt access denied
- [Android开发插件]ADT的下载位置。
- Fast Scrolling in Tweetie with UITableView
- DevExpress控件使用
- 逆序输出
- java调用oracle存储过程传入参数为数组的处理
- 关于module_param()宏 (转)
- POJ 1451
- 【orange】特权级变换总结
- Power designer 15生成sql server 2005/2008列注释
- 【Android游戏开发二十二】(图文详解)游戏中灵活实现动画播放!简述J2me的游戏类库与Android游戏开发!