This app launches in landscape orientation. I took the screenshot while the animation was in progress, so the letter G was caught between screen refreshes.
The app animates the
center
property of a
UILabel
which is a subview of 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
view
controller
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.
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.
AppDelegate.swift
ViewController.swift
.
Added the
AVAudioPlayer
property
and initialized it in the
viewDidLoad
method.
Also added the method
supportedInterfaceOrientations
to launch the app in lanscape orientation.
View.swift
gone.mp3
Info.plist
:
added the
“Initial interface orientation”
property to launch the app in landscape orientation.
Drag the file
gone.mp3
into the Supporting Files folder of the Xcode Project Navigator.
Choose options for adding these files:
Destination: ☑ Copy items if needed.
Add to targets: ☑ Gone
Finish
Then open the Supporting Files folder and make sure
gone.mp3
is listed there in black.
Can you select it and play it?
To launch in landcape orientation, follow the “create the project” directions in Sine.
The application delegate has an instance variable that is an
AVAudioPlayer
.
The file
ViewController.swift
must therefore
import
the module
AVFoundation
.
Surprisingly, we do not have to add the
AVFoundation.framework
to the project.
Turn on the Macintosh sound.
Run the project.
Does the sound stop when you press the simulator’s Home button?
Hardware →
Home
Output produced by
print
on the iPhone Simulator:
bundle.bundlePath = "/Users/myname/Library/Developer/CoreSimulator/Devices/01EBED35-F21B-4B4C-95BC-BFDDDC6264B4/data/Containers/Bundle/Application/DADF37D1-AB36-4C40-B31B-4FD8B023584B/Gone.app" path = "/Users/myname/Library/Developer/CoreSimulator/Devices/01EBED35-F21B-4B4C-95BC-BFDDDC6264B4/data/Containers/Bundle/Application/DADF37D1-AB36-4C40-B31B-4FD8B023584B/Gone.app/gone.mp3" url = "file:///Users/myname/Library/Developer/CoreSimulator/Devices/01EBED35-F21B-4B4C-95BC-BFDDDC6264B4/data/Containers/Bundle/Application/DADF37D1-AB36-4C40-B31B-4FD8B023584B/Gone.app/gone.mp3" player!.numberOfChannels = 2
UILabel
s
(or a single
UITextView
;
see
here)
containing the following two lines.
Animate the
alpha
of the
UILabel
s
from 0.0 to 1.0.
crawl.html
here.