NSPoint\CGPoint
两个double类型的值想,x,y,代表点的坐标位置
创建方式:
创建方式:
CGPoint p1 = NSMakePoint(10, 10);
NSPoint p2 = CGPointMake(20, 20);// 最常用
NSPoint p2 = CGPointMake(20, 20);// 最常用
NSSize\CGSize
一个矩形的大小,wight,high,代表矩形的宽高
创建方式:
创建方式:
NSSize s1 = CGSizeMake(100, 50);
NSSize s2 = NSMakeSize(100, 50);
CGSize s3 = NSMakeSize(200, 60);
NSSize s2 = NSMakeSize(100, 50);
CGSize s3 = NSMakeSize(200, 60);
NSRect\CGRect (CGPint CGSize)
根据点的位置,创建一个矩形,具有位置坐标以及尺寸
创建方式:
CGRect r1 = CGRectMake(0, 0, 100, 50);
CGRect r2 = { {0, 0}, {100, 90}};
CGRect r3 = {p1, s2};
CGRect r2 = { {0, 0}, {100, 90}};
CGRect r3 = {p1, s2};
原点
表示原点
CGPointZero == CGPointMake(0, 0)
CGPointZero == CGPointMake(0, 0)
CGRect r4 = {CGPointZero, CGSizeMake(100, 90)};
将结构体转为字符串
NSString *str = NSStringFromPoint(p1);
NSString *str = NSStringFromSize(s3);
NSString *str = NSStringFromRect(r1);
NSString *str = NSStringFromPoint(p1);
NSString *str = NSStringFromSize(s3);
NSString *str = NSStringFromRect(r1);
注意: 使用这些CGPointEqualToPoint、CGRectContainsPoint、CGPointZero等函数的前提是添加CoreGraphics框架
比较两个点是否相同(x,y):
//CGRectEqualToRect(<#CGRect rect1#>, <#CGRect rect2#>)
//CGSizeEqualToSize(<#CGSize size1#>, <#CGSize size2#>)
//CGSizeEqualToSize(<#CGSize size1#>, <#CGSize size2#>)
BOOL b2 = CGRectContainsPoint(CGRectMake(50, 40, 100, 50), CGPointMake(60, 45));
BOOL b = CGPointEqualToPoint(CGPointMake(10, 10), CGPointMake(10, 10));