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.
main.m
GoneAppDelegate
View
gone.mp3
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
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.
Turn on the Macintosh sound.
Run the project.
Does the sound stop when you press the simulator’s Home button?
Hardware →
Home
UILabel
s
(or a single
UITextView
;
see
here)
containing the following two lines.
Animate the
alpha
of the
UILabel
s
from 0 to 1.
crawl.html
here.