15 Nov 2009
iPhone Tip: Fading Views In and Out
Most iPhone apps have a splash screen. It's a PNG image called Default.png that gets automatically displayed (if present) when an app starts. Apple uses the image to make an app appear to load faster than it actually does, by making the splash screen a screenshot of the initial view.
A couple days ago, I stumbled across an excellent tip for fading out Default.png using Core Animation. The original version faded the image out by expanding it and lowering its alpha value. It's a great effect, but I preferred a more general method. The code below is for a UIViewController subclass and fades out any subview. It brings the subview to the front, reduces the alpha to zero over a half second, then sends the view to the back. I use it to fade out the splash screen after the app launches and to fade out the root table view (thereby displaying the splash screen) if the user deletes all its items.