This app remains motionles for three seconds,
rotates the activity indicator for 10 seconds,
and then stops.
This sequence is stage managed by the
view
controller.
The view controller manipulates the
view
like a marionette.
The strings are the
startAnimating
and
startAnimating
methods of the view.
AppDelegate
:
unchanged.
ViewController
creates two
NSTimer
s.
View
Like the
UISwitch
we saw
here,
we do not have to specify a size for an
UIActivityIndicatorView
.
On iPhone 6, it assumes a default size of
20 × 20
pairs of pixels for
UIActivityIndicatorViewStyle.Gray
,
37 × 37 for
UIActivityIndicatorViewStyle.LargeWhite
.
The gear has 12 teeth. The highlight starts at 9 o’clock and rotates clockwise at the rate of 360° per second. Hide the activity indicator when it has finished so the user won’t think the app has stalled. See Activity Indicator in the Human Interface Guidelines.
An
NSTimer
is like an invisible
UIButton
that is automatically pressed after a certain number of seconds.
When the time is up,
it can call a method of an object.
Unlike the
dispatch_after
we saw
next example.
UIActivityIndicatorViewStyle.LargeWhite
.
Warning: a
UIActivityIndicatorViewStyle.White
or
LargeWhite
indicator on a white background will be totally invisible.
activityIndicatorView.color = UIColor.blueColor();
resume
method of the
download
task,
and stop animating
at the beginning of the completion handler passed to
downloadTaskWithURL(_:completionHandler:)
.