Lecture 05 Iphone Programming
Lecture 05 Iphone Programming
Spring 2010
E-mail
Questions are best sent to [email protected]
Sending directly to instructor or TA’s risks slow response.
Web Site
Very Important!
http://cs193p.stanford.edu
All lectures, assignments, code, etc. will be there.
This site will be your best friend when it comes to getting info.
Views
Core Graphics
Demo
@protocol Foo
- (void)doSomething;
@optional
- (int)getSomething;
@required
- (NSArray *)getManySomethings:(int)howMany;
@end
Hierarchical
Only one superview: - (UIView *)superview
Can have many (or zero) subviews: - (NSArray *)subviews
Subview order matters: those later in the array are on top of earlier
UIWindow
The UIView at the top of the view hierarchy
Only have one UIWindow in an iPhone application (it’s all about views)
But be careful!
If you remove a view from the view hierarchy it may deallocate
immediately (no autorelease happens). So, retain it first, then call
removeFromSuperview.
CGPoint
C struct with two CGFloats in it: x and y.
Create with CGPointMake(x, y)
CGSize
C struct with two CGFloats in it: width and height.
Create with CGSizeMake(width, height)
CGRect
C struct with a CGPoint origin and a CGSize size.
Create with CGRectMake(x, y, width, height)
Coordinates
(0,0)
0,
20
2
0
0
Vi
ew
320
Example:
Or use a UIGestureRecognizer
Concepts
Get a context to draw into
Apply transformations
Create paths
Set colors, fonts, textures, linewidths, linecaps, etc.
Stroke or fill those paths
Delegate
Quartz 2D
Application Delegate
UINavigationController
Homework Explanation