Cggeometry class defines the structure of geometric elements and functions for operating geometric elements.
1. Data Type:
Cgfloat: basic type of floating point value
Cgpoint: points in a two-dimensional coordinate system
Cgsize: indicates the width and height of a rectangle.
Cgrect: the position and size of a rectangle.
typedef float CGFloat;// 32-bittypedef double CGFloat;// 64-bitstruct CGPoint { CGFloat x; CGFloat y;};typedef struct CGPoint CGPoint;struct CGSize { CGFloat width; CGFloat height;};typedef struct CGSize CGSize;struct CGRect { CGPoint origin; CGSize size;};typedef struct CGRect CGRect;
Note: the height and width of the cgrect data structure can be negative. For example, the origin of a rectangle is [0.0, 0.0] And the size is [10.0, 10.0]. This rectangle is exactly the same as the rectangle where the source is [10.0, 10.0] And the size is [-10.0,-10.0.
2. Use values to create geometric elements
Cgpointmake
Cgrectmake
Cgsizemake
CGPoint CGPointMake ( CGFloat x, CGFloat y);CGSize CGSizeMake ( CGFloat width, CGFloat height);CGRect CGRectMake ( CGFloat x, CGFloat y, CGFloat width, CGFloat height);
CGFloat ten=10.0f; CGPoint point = CGPointMake(0.0f, 0.0f); CGSize size = CGSizeMake(10.0f, 10.0f); CGRect rect = CGRectMake(point.x, point.y, size.width, size.height); NSLog(@"ten: %f", ten); NSLog(@"point: %@", NSStringFromCGPoint(point)); NSLog(@"size: %@", NSStringFromCGSize(size)); NSLog(@"rect: %@", NSStringFromCGRect(rect));
Address: http://www.cnblogs.com/chivas/archive/2012/05/16/2504006.html