Graphics Reference
In-Depth Information
Figure 12.12
Our app running at close-to 60 FPS with shadows disabled
Problem solved. Without the shadows, we get a smooth scroll. Our contacts list doesn't
look as interesting as before, though. How can we keep our layer shadows and still have
good performance?
Well, the text and avatar for each row don't need to change every frame, so it seems like
the
UITableViewCell
layer is an excellent candidate for caching. We can cache our layer
contents using the
shouldRasterize
property. This will render the layer once offscreen
and then keep the result until it needs to be updated. Let's try that (see Listing 12.2).
Listing 12.2
Improving Performance with the
shouldRasterize
Option
- (
UITableViewCell
*)tableView:(
UITableView
*)tableView
cellForRowAtIndexPath:(
NSIndexPath
*)indexPath
{
//dequeue cell
UITableViewCell
*cell =
[
self
.
tableView
dequeueReusableCellWithIdentifier
:
@"Cell"
forIndexPath
:indexPath];
...