UIActivityIndicator

Like the UISwitch we saw here, we do not have to specify a size for an UIActivityIndicator. It assumes a default size of 20 × 20 or 37 × 37, depending on its style. The gear has 12 teeth. The highlight starts at 9 o’clock (12 o’clock in older versions of iOS) and rotates clockwise once 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.

The easiest way to center the UIActivityIndicator in the View was to move the View’s origin to the center of the View.

The app remains motionles for three seconds, rotates 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.

The timer

An NSTimer is like an invisible UIButton that is automatically pressed after a certain number of seconds. When the time is up, it can send any message to any object. Unlike the performSelector:withObject:afterDelay: we saw here, the timer can repeat itself automatically. We will use this feature in the next example.

Source code in Activity.zip

  1. main.m
  2. Class ActivityAppDelegate
  3. Class ViewController
  4. Class View