码迷,mamicode.com
首页 > 其他好文 > 详细

CGRectIntersection函数与CGRectIsNull函数

时间:2015-04-28 17:28:52      阅读:453      评论:0      收藏:0      [点我收藏+]

标签:

CGRectIntersection函数可以返回一个CGRect类型的值以表示两个CGRect类型变量的交集部分,如果不存在相交部分则返回CGRectIsNull

可以通过CGRectIsNull函数判断一个CGRect类型的变量是否为CGRectNull

 

示例代码

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        CGRect intersectionRect = CGRectZero;

        CGRect r1 = CGRectMake(100, 100, 200, 200);
        CGRect r2 = CGRectMake(200, 200, 300, 400);
        intersectionRect = CGRectIntersection(r1, r2);
        NSLog(@"CGRectIntersection(r1, r2) = %@", NSStringFromRect(intersectionRect));

        CGRect r3 = CGRectMake(0, 0, 50, 50);
        CGRect r4 = CGRectMake(60, 60, 50, 50);
        intersectionRect = CGRectIntersection(r3, r4);
        NSLog(@"CGRectIntersection(r3, r4) = %@", NSStringFromRect(intersectionRect));
        
        // 可以通过CGRectIsNull函数判断一个CGRect类型的变量是否为CGRectNull
        NSLog(@"%@", CGRectIsNull(CGRectNull) ? @"YES" : @"NO");
    }
    return 0;
}

 

CGRectIntersection函数与CGRectIsNull函数

标签:

原文地址:http://www.cnblogs.com/loftyspirit/p/4463238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!