- The View Hierarchy
- Getting a View to Draw Itself
- Drawing with NSBezierPath
- NSScrollView
- Creating Views Programmatically
- For the More Curious: Cells
- For the More Curious: isFlipped
- Challenge
For the More Curious: isFlipped
Both PDF and PostScript use the standard Cartesian coordinate system, whereby y increases as you move up the page. Quartz follows this model by default. The origin is usually at the lower-left corner of the view.
For some types of drawing, the math becomes easier if the upper-left corner is the origin and y increases as you move down the page. We say that such a view is flipped.
To flip a view, you override isFlipped in your view class to return YES:
- (BOOL)isFlipped { return YES; }
While we are discussing the coordinate system, note that x- and y-coordinates are measured in points. A point is typically defined as 72.0 points = 1 inch. In reality, by default 1.0 point = 1 pixel on your screen. You can, however, change the size of a point by changing the coordinate system:
// Make everything in the view twice as large NSSize newScale; newScale.width = 2.0; newScale.height = 2.0; [myView scaleUnitSquareToSize:newScale]; [myView setNeedsDisplay:YES];