直接上代码。看有些边界上的点在,有些却不在
- #import <Foundation/Foundation.h>
- int main(int argc, const char * argv[])
- {
- // 点(0,0)包含在矩形(0,0,10,20)中
- bool b1 = CGRectContainsPoint(CGRectMake(0,0,10,20),CGPointMake(0,0));
- NSLog(@"b1 = %i",b1);
-
- // 点(10,20)不包含在矩形(0,0,10,20)中
- bool b2 = CGRectContainsPoint(CGRectMake(0,0,10,20),CGPointMake(10,20));
- NSLog(@"b2 = %i",b2);
-
- // 点(10,0)不包含在矩形(0,0,10,20)中
- bool b3 = CGRectContainsPoint(CGRectMake(0,0,10,20),CGPointMake(10,0));
- NSLog(@"b3 = %i",b3);
-
- // 点(5,0)包含在矩形(0,0,10,20)中
- bool b4 = CGRectContainsPoint(CGRectMake(0,0,10,20),CGPointMake(5,0));
- NSLog(@"b4 = %i",b4);
-
- // 点(0,20)不包含在矩形(0,0,10,20)中
- bool b5 = CGRectContainsPoint(CGRectMake(0,0,10,20),CGPointMake(0,20));
- NSLog(@"b5 = %i",b5);
-
- // 点(0,10)包含在矩形(0,0,10,20)中
- bool b6 = CGRectContainsPoint(CGRectMake(0,0,10,20),CGPointMake(0,10));
- NSLog(@"b6 = %i",b6);
-
-
-
- return 0;
- }
复制代码 |
|