Fast Scrolling in Tweetie with UITableView

 

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.

 

内容概要:本文详细介绍了在Linux环境下进行C++开发所需掌握的内容,以一个Web多人聊天项目为例,涵盖从开发环境搭建到项目部署的全过程。首先推荐了一个项目地址,该项目支持HTTP请求、Websocket、多房间和多人聊天、MySQL用户信息存储、Redis缓存、json序列化等功能,并建议扩展功能如基于Reactor模型构建HTTP/Websocket服务、仿写MySQL/Redis连接池等。接着介绍了开发环境,包括Ubuntu 20.04、MySQL 8.0、Redis 6.0、gcc/g++ 10.5.0等,并提供了详细的部署步骤,如安装boost库、编译聊天室服务、配置MySQL和Redis等。最后分析了项目架构,包括数据存储(MySQL存储用户信息,Redis存储房间消息和用户cookie)、消息格式(HTTP请求消息和Websocket交互消息)、HTTP/Websocket数据处理流程等。; 适合人群:有一定Linux基础,想深入了解C++开发及网络编程的开发者,尤其是有志于从事Web开发或服务器端开发的技术人员。; 使用场景及目标:①掌握Linux C++开发环境的搭建,包括工具链的安装与配置;②理解并实践HTTP、Websocket等网络协议的应用;③熟悉MySQL、Redis等数据库的使用;④学习如何处理HTTP请求、Websocket交互消息及数据存储;⑤能够独立完成类似Web聊天室的项目开发。; 其他说明:本文不仅提供了理论指导,还给出了具体的实践操作步骤,如编译过程中可能遇到的问题及解决方案。对于初学者来说,可以按照文中提供的链接和教程逐步学习,同时鼓励读者根据自身需求对项目进行扩展和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值