The coordinate system is not cartesian based starting in the lower left corner. In iOS the origin is the upper left corner.
* (500, 35) is right 500 points, down 35 points
Units are points, not pixels
- Pixels are the minimum-sized unit of drawing your device is capable of
- Points are the units in the coordinate system
- Most of the time there are 2 pixels per point, but it could be only 1 or even 3.
- We can find out how many pixels per point are there with UIView's
var contentScaleFactor: CGFloat
- Most of the time we don't need to worry about points vs. pixels because iOS takes care of it.
The boundaries of where drawing happens is contained in a very important var called bounds
. This is a view's internal drawing space's origin and size, or in other words the rectangle containing the drawing space in its own coordinate system.
- It's up to the view's implementation to interpret what
bounds.origin
means (often nothing) var center: CGPoint
andvar frame: CGRect
have nothing to do with where we are drawing. They are never used to draw inside a view's coordinate system. They deal with where we are in the superview.center
is the center of a UIView in it's superview's coordinate system, andframe
is the rect containing a UIView in its superview's coordinate system.- We might be inclined to think
frame.size
is always equal tobounds.size
but that's not accurate because view's can be rotated (and scaled and translated). - Views are rarely rotated, but it's important to not misuse
frame
andcenter
by assuming that.
View B's bounds = ((0,0), (200,250))
View B's frame = ((140, 65), (320, 320)
View B's center = (300, 225)
View B's middle in its own coordinate is (bounds.midX, bounds.midY) = (100, 125)