Gone

We will animate the center property of a UILabel contained in another UIView. The label has white letters and a clear background; the view has a blue background and nothing else.

We put the audio code in the application delegate because a subclass of UIView should concentrate on matters such as background color and fonts. A view should be seen and not heard. The audio code does not belong in the application delegate either. The application delegate should concentrate on lifecycle events—startup and termination. The audio code really belongs in a view controller.

We didn’t need to search for the image file in America using an NSBundle. But we do need to search for the sound file here using a NSBundle, because we need the full pathname of the sound file in order to create the NSURL object. Title sequence from the Gone With the Wind movie.

Source code in Gone.zip

  1. main.m
  2. Class GoneAppDelegate
  3. Class View
  4. gone.mp3

Create the project

The application delegate has an instance variable that is an AVAudioPlayer. The file GoneAppDelegate.h must therefore import the header file AVFoundation/AVAudioPlayer.h. Older Xcodes required us to add the AVFoundation.framework to the project, but that is no longer necessary. We should be able to get along with the four frameworks that are already in the Frameworks folder of the Project navigator.

Put the gone.mp3 file on your Macintosh desktop. Then drag it into the Supporting Files folder of the Xcode Project Navigator.

Choose options for adding these files
Destination ☑ copy items into destiation group’s folder (if needed)
Finish

Then open the Supporting Files folder and make sure gone.mp3 is listed there in black.

Run the project

Turn on the Macintosh sound. Run the project. Does the sound stop when you press the simulator’s Home button?
Hardware → Home

Things to try

  1. Fade in a pair of UILabels (or a single UITextView; see here) containing the following two lines. Animate the alpha of the UILabels from 0 to 1.

    David O. Selznick
    Presents

  2. Animate the STAR WARS logo receding from the viewer, with background music.


  3. It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire. During the battle, Rebel spies managed to steal secret plans to the Empire’s ultimate weapon, the Death Star, an armored space station with enough power to destroy an entire planet. Pursued by the Empire’s sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy… See crawl.html here.