2011年11月19日 星期六

Stanford CS193p Fall 2011 Note-04

Instance vs. Class Methods

Instance Methods:
1. Starts with a dash:
   - (BOOL)dropBomb:(Bomb *)bomb
                                    at:(CGPoint)position
                               from:(double)altitude;

2. "Normal" Instance Methods

3. Calling syntax:
     [<pointer to instance> method]
     e.g.
     Ship *ship = ...; // instance of a Ship
     destroyed = [ship dropBomb:firecracker
                                                      at:dropPoint
                                               from:300.0];

4. self/super is calling instance
    self means "my implementation"
    super means "my superclass's implementation"

Class Methods:
1. Starts with a plus sign:
   + (id) alloc;
   + (Ship *)motherShip;
   + (NSString *)stringWithFormat:...

2. Creation & Utility Methods

3. Calling syntax:
    [Class method]
    e.g.
    Ship *ship = [Ship motherShip];
    NSString *resultString =
    [NSString stringWithFormat:@"%g", result];
    [[ship class] doSomething];

4. self/super is this class
    self means "this class's class methods"
    super means "this class's superclass's class methods"

-----------------------------------------------------------------------------

Coordinates
1. bounds // @property CGRect bounds;
   a. your view's internal drawing space's origin and size
   b. The bounds property is what you use inside your view's own implementation.
   c. It is up to your implementation as to how to interpret the meaning of
       bounds.origin.
       e.g. View B's bounds = ((0,0),(200,250)) // ((x, y), (width, height))  

2. center // @property CGPoint center;
    the center of your view in your superview's coordinate space
     e.g. View B's center = (300,225) // (x, y)

3. frame // @property CGRect frame;
    a rectangle in your superview's coordinate space which entirely contains your
    view's bounds.size
    e.g. View B's frame = ((140,65),(320,320)) // ((x, y), (width, height))

4. Use frame and center to position the view in the hierarchy
    a. These are used by superviews, never inside your UIView subclass's
        implementation.
    b. You might think frame.size is always equal to bounds.size, but you'd be wrong ...
        Because views can be rotated (and scaled and translated too).

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。