iOS开发 ☞ 各种CG结构体
来源:互联网 发布:python开发的网站源码 编辑:程序博客网 时间:2024/06/03 17:27
1、CGRectInset(<#CGRect rect#>, <#CGFloat dx#>, <#CGFloat dy#>)
中心相同
CG_EXTERN CGRect CGRectInset(CGRect rect, CGFloat dx, CGFloat dy) CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
UIView *view = [[UIView alloc] init]; view.frame = CGRectMake(100, 100, 100, 100); view.backgroundColor = [UIColor orangeColor]; UIView *otherView = [[UIView alloc] init]; otherView.frame = CGRectInset(view.frame, 2, 4); otherView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:view]; [self.view addSubview:otherView];
2、CGRectOffset(<#CGRect rect#>, <#CGFloat dx#>, <#CGFloat dy#>)
位置不同
CG_EXTERN CGRect CGRectOffset(CGRect rect, CGFloat dx, CGFloat dy) CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
UIView *view = [[UIView alloc] init]; view.frame = CGRectMake(100, 100, 100, 100); view.backgroundColor = [UIColor purpleColor]; UIView *otherView = [[UIView alloc] init]; otherView.frame = CGRectOffset(view.frame, 2, 4); otherView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:view]; [self.view addSubview:otherView];
3、CGRectGetMidY(<#CGRect rect#>) 、 CGRectGetMidX(<#CGRect rect#>)
获取中心点坐标
CG_EXTERN CGFloat CGRectGetMidX(CGRect rect) CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0); CG_EXTERN CGFloat CGRectGetMidY(CGRect rect) CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
UIView *view = [[UIView alloc] init]; view.frame = CGRectMake(100, 100, 100, 100); view.backgroundColor = [UIColor purpleColor]; UIView *otherView = [[UIView alloc] init]; otherView.frame = CGRectOffset(view.frame, 2, 4); otherView.backgroundColor = [UIColor yellowColor]; CGFloat centerX = CGRectGetMidX(view.frame); CGFloat centerY = CGRectGetMidX(view.frame); NSLog(@"%f",centerX); NSLog(@"%f",centerY); [self.view addSubview:view]; [self.view addSubview:otherView];
4、CGRectIntersectsRect(<#CGRect rect1#>, <#CGRect rect2#>)
是否相交
In English,intersect means 交集
CG_EXTERN bool CGRectIntersectsRect(CGRect rect1, CGRect rect2) CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
UIView *view = [[UIView alloc] init]; view.frame = CGRectMake(100, 100, 100, 100); view.backgroundColor = [UIColor purpleColor]; UIView *otherView = [[UIView alloc] init]; otherView.frame = CGRectOffset(view.frame, 2, 4); otherView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:view]; [self.view addSubview:otherView]; BOOL isIntersect = CGRectIntersectsRect(view.frame, otherView.frame); NSLog(@"%d",isIntersect);
5、CGRectIntersection(<#CGRect r1#>, <#CGRect r2#>)
相交区域
CG_EXTERN CGRect CGRectIntersection(CGRect r1, CGRect r2) CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
UIView *view = [[UIView alloc] init]; view.frame = CGRectMake(100, 100, 100, 100); view.backgroundColor = [UIColor purpleColor]; UIView *otherView = [[UIView alloc] init]; otherView.frame = CGRectOffset(view.frame, 2, 4); otherView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:view]; [self.view addSubview:otherView]; CGRect rect = CGRectIntersection(view.frame, otherView.frame); NSLog(@"%@",NSStringFromCGRect(rect)); UIView *intersectView = [[UIView alloc] init]; intersectView.frame = rect; intersectView.backgroundColor = [UIColor redColor]; [self.view addSubview:intersectView];
6、CGRectIsNull(<#CGRect rect#>)
是否为空
CG_EXTERN bool CGRectIsNull(CGRect rect) CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
UIView *view = [[UIView alloc] init]; view.frame = CGRectMake(100, 100, 100, 100); view.backgroundColor = [UIColor orangeColor]; [self.view addSubview:view]; UIView *view1 = [[UIView alloc] init]; view1.frame = CGRectMake(100, 150, 100, 100); view.backgroundColor = [UIColor yellowColor]; [self.view addSubview:view1]; CGRect intersectRect = CGRectIntersection(view.frame, view1.frame); //0说明有交集 NSLog(@"%d",CGRectIsNull(intersectRect));
7、CGRectEqualToRect(<#CGRect rect1#>, <#CGRect rect2#>)
判断两个矩形是否相同,包括位置和形状
CG_EXTERN bool CGRectEqualToRect(CGRect rect1, CGRect rect2) CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
2016年12月21日更新
iOS中的坐标转换:
经常遇到的需求是把cell上的子视图的坐标转为窗口的坐标,我们需要的转换如下:
[cell convertPoint:tmpImage.center toView:destinationView] 这里的cell的位置不能传入子视图的坐标,需要注意一下。
1 0
- iOS开发 ☞ 各种CG结构体
- iOS开发中,bounds和frame的区别。iOS开发结构体属性值查看和控制器各种尺寸的获取小技巧。
- IOS开发各种
- ios开发 各种字体
- IOS开发---C语言-⑮结构体
- iOS开发之结构体设置
- iOS开发关系结构体分配空间
- IOS开发笔记13-结构体
- iOS开发-前言篇C-结构体
- IOS开发之结构体的使用
- 开发词典(CG)
- Cg开发环境搭建
- iOS开发-工程结构
- iOS开发-各种动画效果
- IOS开发各种疑难 二
- IOS开发的各种坑
- iOS开发各种证书问题
- iOS开发各种证书问题
- java-使用字符串输出对象
- 上传excel中的内容到服务器
- kvm 虚拟化 virt-install 安装虚拟机
- Centos 6.5 - Red Hat 6.5 时区更改
- ruby on rails ,extjs框架下的ajax使用
- iOS开发 ☞ 各种CG结构体
- 相对路径与绝对路径
- Linux死锁调试之softlockup
- Fragment和Activity之间的数据传递(两种:Acitvity-->Fragment;Fragment---->Activity)
- JVM学习总结--体系结构、内存管理和垃圾回收
- ViewHolder模式
- 你的第一个网页
- untiy 3d ShaderLab_第7章_ Forward渲染路径_1_ForwardBase和ForwardAdd
- cmd used in sql tests (sql学习指南)