Recipe: Fading a View In and Out

At times, you want to add information to your screen that overlays your view but does not of itself do anything. For example, you might show a top-scores list or some instructions or provide a context-sensitive tooltip. Recipe 4-6 demonstrates how to use a UIView animation block to fade a view into and out of sight. This recipe follows the most basic animation approach. It creates a view animation block that sets the alpha property.

Note how this code controls the behavior of the right bar button item. When tapped, it is immediately disabled until the animation concludes. The animation’s completion block reenables the button and flips the button text and callback selector to the opposite state. This allows the ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.