Lecture 4

Lecture 4 - Stanford CS193p Fall 2011 Stanford CS193p...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Stanford CS193p Fall 2011 Stanford CS193p Developing Applications for iOS Fall 2011 Stanford CS193p Fall 2011 Views A view (i.e. UIView subclass) represents a rectangular area Denes a coordinate space Draws and handles events in that rectangle Hierarchical A view has only one superview - (UIView *)superview But can have many (or zero) subviews - (NSArray *)subviews Subview order (in subviews array) matters: those later in the array are on top of those earlier UIWindow The UIView at the top of the view hierarchy Only have one UIWindow (generally) in an iOS application Its all about views, not windows Stanford CS193p Fall 2011 Views The hierarchy is most often constructed in Xcode graphically Even custom views are added to the view hierarchy using Xcode (more on this later). But it can be done in code as well- (void)addSubview:(UIView *)aView;- (void)removeFromSuperview; Stanford CS193p Fall 2011 View Coordinates CGFloat Just a oating point number, but we always use it for graphics. CGPoint C struct with two CGFloat s in it: x and y . CGPoint p = CGPointMake(34.5, 22.0); p.x += 20; // move right by 20 points CGSize C struct with two CGFloat s in it: width and height . CGSize s = CGSizeMake(100.0, 200.0); s.height += 50; // make the size 50 points taller CGRect C struct with a CGPoint origin and a CGSize size . CGRect aRect = CGRectMake(45.0, 75.5, 300, 500); aRect.size.height += 45; // make the rectangle 45 points taller aRect.origin.x += 30; // move the rectangle to the right 30 points Stanford CS193p Fall 2011 (0,0) increasing x i n c r e a s i n g y Coordinates Origin of a views coordinate system is upper left Units are points (not pixels) Usually you dont care about how many pixels per point are on the screen youre drawing on. Fonts and arcs and such automatically adjust to use higher resolution. However, if you are drawing something detailed (like a graph, hint, hint), you might want to know. There is a UIView property which will tell you: @property CGFloat contentScaleFactor; // returns pixels per point on the screen this view is on This property is not (readonly) , but you should basically pretend that it is for this course. Views have 3 properties related to their location and size @property CGRect bounds; // your views internal drawing spaces origin and size The bounds property is what you use inside your views own implementation. It is up to your implementation as to how to interpret the meaning of bounds.origin . @property CGPoint center; // the center of your view in your superview s coordinate space @property CGRect frame; // a rectangle in your superview s coordinate space which entirely // contains your views bounds.size (400, 35) Stanford CS193p Fall 2011 Coordinates Use frame and center to position the view in the hierarchy These are used by superview s, never inside your UIView subclasss implementation....
View Full Document

Page1 / 24

Lecture 4 - Stanford CS193p Fall 2011 Stanford CS193p...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online