An app must be written in the language Objective-C. You type the app into Xcode, an application which runs on a Mac. Test the app in the iPhone simulator, which also runs on the Mac. Debug the app in the Xcode debugger. Then download the app to your iPhone, iPad, or iPod Touch.
Hello
:
the “Hello, World!” app prints
“Hello, World!”.
You can install your own
font.
.zip
files.zip
and
unzip
.
You don’t have to do this for this course,
but it’s something you might need to know.
We printed a line of text in the
drawRect:
method of class
UIView
in the
Hello
app.
Now let’s draw a picture.
Japan
:
a simple still life.Manhattan
:
an outline.America
:
draw and fill a rectangle with
CGContextAddRect
.
Draw an image with
UIImage
drawAtPoint:
.
Sine
:
graph the sine function,
with a
pattern
in the background.
Touch
:
detect a touch, move a hockey puck.
The methods
touchesBegan:withEvent:
,
touchesMoved:withEvent:
,
touchesEnded:withEvent:
receive an
NSSet
containing
UITouch
objects.
UILabel
displays a line of text.Gone
:
animate the
center
property of a
UILabel
contained in a
UIView
.
Etch
:CGMutablePathRef
we saw in the
isoceles right triangle
example.
Hit
:
which of several subviews were touched?Flip
.
Flip
:
transition between two views in response to a swipe.
Although this example has no view controller,
it belongs thematically in the section
“View controlers that manage other view controllers” below.
I put it here because everybody wants to transition between views
as early as possible in the course.
Puzzle
:
classic puzzle of 8 movable tiles in a 3 × 3 square with one missing.
See
Gesture
Recognizers,
the superclass
UIGestureRecognizer
,
and
Interactivity
and Feedback.
UITextView
:
a class that displays multiple lines of text.
UISwipeGestureRecognizer
.
It has the property
direction
.UIPinchGestureRecognizer
.Tap
:
recognize a single or double (or triple) tap with a
UITapGestureRecognizer
.
It has the property
numberOfTapsRequired
and the method
requireGestureRecognizerToFail:
.
Media files are stored in the app’s “bundle” in the iPhone’s flash memory. We will have to find the directory that holds the bundle and the files in the directory.
gone.mp3
in
Gone.NSData
object.
Some controls
(button,
page
control,
slider,
text
field)
allow you to specify their
size.
Other controls
(switch,
segmented
control,
date
picker)
have a preferred size:
you can set their
position
but not their
size.
The only way to make them bigger or smaller is by putting a
scaling factor
in their
transform
property.
Button
,
the simplest control.
When the button is pressed,
it can
NSLog
a message,
vibrate
the iPhone,
or play an
audio
file.Notification
center:
needed for video.Video
:
play a video file when the button is pressed.Switch
and
AVAudioPlayer
.
The switch has a target;
the
audio
player
has a
delegate.PageControl
:
a row of dots.Slider
Segmented
:
a row of buttons.
Classes
AVAudioSession
,
AVAudioRecorder
,
AVAudioPlayer
.
DatePicker
and its
date
formatter
and
calendar:
pick a
date
or time.UITextField
and its
delegate:
input one line of text.
Every view controller class is a subclass of
UIViewController
.
MVC
stands for
model-view-controller.
ViewController
:
a portrait/landscape view controller.
Pong
:
animation with
CADisplayLink
.Every view controller has a black tab bar item and a brushed aluminum navigation item. The tab bar item becomes visible only when the view controller is under a tab bar controller, and the navigation item becomes visible only when the view controller is under a navigation controller. The three above examples had no tab bar controller or navigation controller (except for a brief presentation in the portrait/landscape view controller).
Projects.zip
:
five student projects controlled by one tab bar controller.viewDidAppear:
and off with
viewWillDisappear:
.
Navigate
:
each successive view enters from the right.
Make a stack of train stations.
Modal
controller:
visit a controller temporarily,
and then return to the previous controller.
The temporary controller enters from the bottom.
LTrain
:
move horizontally with a navigation controller,
vertically with a modal view controller.
Float like a butterfly,
sting like a bee.
layoutSubviews
.UISplitViewController
for iPad has two view controllers underneath it,
master and detail.MPMoviePlayerController
(which we saw here)
must be a
MPMoviePlayerViewController
.
Also demonstrates
UITabBarControllerDelegate
.UITableView
must be a
UITableViewController
(which we will see here).UIImagePickerController
will come
here.
Every view class is a subclass of
UIView
.
Some views are still lifes:
UILabel
,
UIImageView
,
and
UIWebView
.
Some display changing output:
UIActivityIndicatorView
,
UIProgressView
.
Some demand input:
UIAlertView
,
UIActionSheet
,
and
UIPickerView
.
Some perform both input and output:
UITextView
and
UITableView
.
UILabel
was used in
Label
(stationary)
and
Gone
(animated).
UITextView
that we can
edit,
and its
delegate.
Write the text to a file.UIImageView
holds a
UIImage
,
as
UILabel
holds an
NSString
.
See
Pinch,
Puzzle,
Orson.NSTimer
,
too.UIAlertView
and
UIActionSheet
.
UIAlertView
,
UIActionSheet
,
and their delegates.
Terminate the application and launch another one.
UIPickerView
examples.
UIPickerView
has rotating drums like a Las Vegas slot machine.
UIPickerViewDataSource
,
UIPickerViewDelegate
.
UIPickerView
.
The Official Movie Plot Generator
by the Brothers Heimberg:
Justin and Jason.
Search Bar
and its delegate.MKMapView
will be covered down in the maps section.
A
UITableView
is a menu of
UITableViewCell
s.
See
Table
View Programming Guide for iPhone OS.
The Android equivalent is
ListView
.
Settings → General
.
NSIndexPath
contains a pair of numbers:
section
and
row
.States
:
provide the
UITableView
with a
table view controller,
which will also act as the
table view data source
and the
table view delegate.
Section
:
divide the table view into sections.
Each section can have a title.
Goner
:
delete a row from a
UITableView
.Reorder
the rows in a
UITableView
.Correct
the spelling errors in a
UITableView
.Insert
:
insert, delete, reorder.Tree
: a tree of data.
A
UINavigationController
on top of a stack of
UITableViewController
s.Class
UIWebView
and protocol
UIWebViewDelegate
.
The
HIG.
for
loop.UIWebViewDelegate
says that the page is fully loaded before trying to execute the JavaScript.
Map
:
get the latitude and longitude from a
CLLocationManager
.
Give the latitude and longitude to a
MKMapView
,
which displays a
Google map without using
JavaScript,
and to a
CLGeocoder
,
which translates the latitude and longitude into a street address.
Display the street address in an
MKAnnotation
.
Annotations and overlays.CMMotionManager
uses accelerometer and gyroscope data
to compute the device’s attitude.SQL stands for Structed Query Language. It comes in several flavors: MySQL, SQLite, etc. An SQLite database can be stored in the iPone and read and written by an app.
sqlite
using the interactive shell in the Macintosh Terminal window.Base
:
an app that creates, writes, and reads a database.UITextView
or
UIWebView
replaced by a
UITableView
.Zip
:
a database with zipcode, city, state, latitude, longitude, county.Distance
:
find all zipcodes within 5 miles of a given zipcode.Blob
:
“binary large object”
such as an image file.
drawRect:
.This section has only enough lighting and color to show us what’s going on.
Color
GL_TRIANGLE_STRIP
,
glDrawElements
instead of
glDrawArrays
.
glOrthof
,
perspective with
glFrustumf
.
Field of view.glMatrixMode(GL_MODELVIEW)
.
glEnableClientState(GL_COLOR_ARRAY)
.GL_FLAT
and
GL_SMOOTH
.glEnable(GL_LIGHTING)
.
The three components of a light source:
specular, diffuse, ambient.
Spotlights with
GL_SPOT_DIRECTION
,
GL_SPOT_CUTOFF
.
Vertex normals:
GL_NORMAL_ARRAY
,
glNormalPointer
.
GL_SHININESS
.
Objects that glow in the dark with
GL_EMISSION
.
glBlendFunc
.
Generate names (actually ID numbers) for the textures.
Bind the textures with
glBindTexture
;
specify linear scaling.
Load a texture from a
UIImage
object or a PVRCT file.
Pad the image to satisfy the aspect ratio requirements.
Specify the texture coördinates of each vertex by
mapping the ST axes onto the UV axes;
make sure the picture isn’t upside down.
Tile a texture:
GL_REPEAT
is better than
GL_CLAMP_TO_EDGE
.
i5.nyu.edu
.i5.nyu.edu
)
using HTTP PUT.Camera
:
get an image or movie from the camera,
photo albums, or saved photos.Button
.
AVAudioPlayer
,
for background music.
Our examples were
Gone
and
Switch
.
Queue
:
Audio
Queue
for sound that can be synchronized with graphics.
@property
creates an instance variable with the
same name
as the property,
but with a leading underscore.
Should all instance variables have leading underscores?
Don’t need
@synthesize
any more.
App delegate doesn’t need
_window
instance variable any more.
textFieldShouldReturn:
make?