background preloader

Performances graphiques

Facebook Twitter

Glassy Scrolling with UITableView. Now that the veil of secrecy has been lifted, I think it’s time to share at least one bit of information that I’ve gleaned whilst writing my new iPhone application: how to do fast tables. NOTE: If you’re not already familiar with how UITableView works, the rest of this might just sound like jibberish. But I think there’s still valid life advice in here, so please read on! In fact, one of the reasons I even started to write my app was to prove that I could write an app that does super-fast tables. And in my app (which, yes, is still not-to-be-named), I even do my own rich text layout for every cell. And every cell is a different height. Even I was skeptical that I’d be able to pull of fast tables, but it worked out.

How did I accomplish this? Use Views Sparingly I’m not quite sure what’s going on in UIView. For simple table views (settings, or profiles, etc.) you probably can get away with using views with subviews. Use Opaque Views If you have a transparent cell, this can slow you down. More Glassy Scrolling with UITableView. A few days ago I wrote about how to help make your table views scroll more smoothly. The tips and tricks in there definitely work, but I’ve just added another layer of smoothness on top of that. It’s rather heavy-handed, but I thought I’d throw it out there anyway.

It starts much the same, use a single view for your cell and do all your own drawing. The ultimate solution presented here though is to cache the whole damned view contents. Revolutionary? No. In my case I’m slowed down a bit by database fetches, text layout, and rounded images with shadows. It should be noted this should really only be used as a last resort due to the increase in memory required. In order to use this method, you need to be able to uniquely identify a cell by some sort of ID (in my case it’s an NSNumber).

This is actually more expensive to draw in two ways: But the advantage is that we have the caches around for more than just the visible cells (which is all UITableView cares about). Anyway, there you have it. Fun shadow effects using custom CALayer shadowPaths | iOS/Web Developer's Life in Beta. Shadowed view using a rectangular shadowPath I recently had to improve the performance of a few views that utilized CALayer-based shadows on rounded-rect UIView objects. On this particular iPad application, when the device was rotated, the views rotated quite a lot slower than we would have hoped. It wasn’t a show-stopper, but the jerky rotation animation made it look cheap and unpolished. The easiest way to have our cake, and eat it too, was to set a custom CGPath to the layer’s shadowPath property.

This told UIKit to set the inside of the path to opaque, reducing the amount of work the rendering engine needed to perform. The resulting image, as you can see above, has a shadow as you’d expect. Through that process however, I decided to see what sort of effects I could pull off by passing in a path other than the default rectangular bounds of the layer. Trapezoidal CGPath Trapezoidal shadow providing the illusion of depth Elliptical CGPath Paper-curl effect. Fast Scrolling in Tweetie with UITableView. 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. Why it’s Fast Much like on Mac OS X, there are two drawing systems on the iPhone. The GPU on the iPhone hates blending, that’s why Apple recommends that you keep as many of your views opaque as possible. What’s a developer to do? The Code I put together a small example project showing off this technique. 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.