文档介绍:CS193P - Lecture 5
iPhone Application Development
Views
Drawing
Animation
Tuesday, January 19, 2010 1
Announcements
• Assignment 1 grades are out. Contact Paul or Dave if you didn’t
get yours
• Contact Paul or Dave if you need a loaner iPod Touch
• Assignments 2A and 2B due Wednesday, 1/20
Tuesday, January 19, 2010 2
Questions from Monday?
• Model, View, Controller
• Interface Builder & Nibs
• Delegate
■ Allows one object to act on behalf of another object
• Target-Action
Tuesday, January 19, 2010 3
Today’s Topics
• Views
• Drawing
• Text & Images
• Animation
Tuesday, January 19, 2010 4
Views
Tuesday, January 19, 2010 5
View Fundamentals
• Rectangular area on screen
• Draws content
• Handles events
• Subclass of UIResponder (event handling class)
• Views arranged hierarchically
■ every view has one superview
■ every view has zero or more subviews
Tuesday, January 19, 2010 6
View Hierarchy - UIWindow
• Views live inside of a window
• UIWindow is actually just a view
■ adds some additional functionality specific to top level view
• One UIWindow for an iPhone app
■ Contains the entire view hierarchy
■ Set up by default in Xcode template project
Tuesday, January 19, 2010 7
View Hierarchy - Manipulation
• Add/remove views in IB or using UIView methods
- (void)addSubview:(UIView *)view;
- (void)removeFromSuperview;
• Manipulate the view hierarchy manually:
- (void)insertSubview:(UIView *)view atIndex:(int)index;
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)view;
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)view;
- (void)exchangeSubviewAtIndex:(int)index
withSubviewAtIndex:(int)otherIndex;
Tuesday, January 19, 2010 8
View Hierarchy - Ownership
• Superviews retain their subviews
• Not mon for views to only be retained by superview
■ Be careful when removing!
■ Retain subview before removing if you want to reuse it
• Views can be temporarily