

In Instruments, check Color Misaligned Images to hunt for accidental anti-aliasing. Instead, run floor or ceil on computed values. Core Animation will accept this, but it will require anti-aliasing, which is expensive. If width is an odd number, then subFrame will have a fractional width. The green area indicates opaque the red areas point to blended surfaces.ĬGRect subframe = CGRectMake(x, y, width / 2.0, height / 2.0) To quickly spot blending, select the Color Blended Layers option under Instruments in the Core Animation instrument. We solved this by reducing the area Core Animation has to consider non-opaque, by splitting the shadow areas from content area of the cell.

This presented a challenge, as blending is expensive. You’ll notice that Tweets in Twitter for iPhone 4.0 have a drop shadow on top of a subtle textured background. This is, by far, the most commonly used cell in the app. We institutionalized direct drawing by creating a generic table view cell class that accepts a block for its drawRect:method. Instead, our Tweet cells contain a single view with no subviews a single drawRect: draws everything. Unfortunately, each view burdens Core Animation with extra compositing. Consider the following Tweet: Use direct drawingĪ naive implementation of a Tweet cell might include a UILabel for the username, a UILabel for the tweet text, a UIImageView for the avatar, and so on. The most common reasons may be excessive compositing, blending, or pixel misalignment. When the GPU is overburdened, it manifests with low, but consistent, framerates. The following sections contain simple directives, based on how we addressed each of these challenges. Either the GPU is being taxed by expensive operations, or the CPU is spending too much time preparing the cell before handing it off to the GPU. Everything in your view’s drawRect: is handled by the CPU, then handed off to the GPU as a texture.Īnimation problems fall into one of those two phases in the pipeline. However, the GPU is not optimized for drawing. When animating layers, the GPU just transforms surfaces as an extended function of the hardware itself. Layers are a simple abstraction for working with the GPU. A review of layersĪnimation on iOS is powered by Core Animation layers. If you are troubleshooting animation performance, this post should provide some useful pointers. The new UI of Twitter for iPhone 4.0 contains many details that could impact performance, so we had to treat 60 frame-per-second animation as a priority. However, jerky scrolling ruins the experience. While many mobile platforms have touch, it is the realistic physics and fluid animation of the iPhone that sets it apart from its competitors. The iPhone was revolutionary for its use of direct manipulation – the feeling that you’re really holding content in your hands and manipulating it with your fingertips.
