美文网首页
iOS开发中坐标系的转换

iOS开发中坐标系的转换

作者: 几分心动i | 来源:发表于2017-11-09 10:48 被阅读0次

一.官方方法

// 将像素point由point所在视图转换到目标视图view中,返回在目标视图view中的像素值
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
// 将像素point从view中转换到当前视图中,返回在当前视图中的像素值
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;

// 将rect由rect所在视图转换到目标视图view中,返回在目标视图view中的rect
- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;
// 将rect从view中转换到当前视图中,返回在当前视图中的rect
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;

二.使用示例

1.场景图
[图片上传失败...(image-7ceef2-1510195738500)]

2.代码

 NSLog(@"SelfView:%@",NSStringFromCGRect(self.view.frame));
 NSLog(@"Red:%@",NSStringFromCGRect(_redView.frame));
 NSLog(@"Green:%@",NSStringFromCGRect(_greenView.frame));
 NSLog(@"Yellow:%@",NSStringFromCGRect(_yellowView.frame));

 CGPoint greenToSelf1 = [_redView convertPoint:_greenView.frame.origin toView:self.view];
 NSLog(@"%@",NSStringFromCGPoint(greenToSelf1));
 CGPoint greenToSelf2 = [self.view convertPoint:_greenView.frame.origin fromView:_redView];
 NSLog(@"%@",NSStringFromCGPoint(greenToSelf2));
 
 CGRect yellowToRed1 = [_greenView convertRect:_yellowView.frame toView:_redView];
 NSLog(@"%@",NSStringFromCGRect(yellowToRed1));
 CGRect yellowToRed2 = [_redView convertRect:_yellowView.frame fromView:_greenView];
 NSLog(@"%@",NSStringFromCGRect(yellowToRed2));

3.输出结果

2017-11-09 10:32:46.059083+0800 KeyBoardNotification[2924:799686] SelfView:{{0, 0}, {414, 736}}
2017-11-09 10:32:46.059150+0800 KeyBoardNotification[2924:799686] Red:{{100, 20}, {200, 200}}
2017-11-09 10:32:46.059173+0800 KeyBoardNotification[2924:799686] Green:{{50, 20}, {100, 100}}
2017-11-09 10:32:46.059194+0800 KeyBoardNotification[2924:799686] Yellow:{{25, 20}, {50, 50}}
2017-11-09 10:32:46.059223+0800 KeyBoardNotification[2924:799686] {150, 40}
2017-11-09 10:32:46.059244+0800 KeyBoardNotification[2924:799686] {150, 40}
2017-11-09 10:32:46.059268+0800 KeyBoardNotification[2924:799686] {{75, 40}, {50, 50}}
2017-11-09 10:32:46.059289+0800 KeyBoardNotification[2924:799686] {{75, 40}, {50, 50}}

相关文章

  • iOS开发中坐标系的转换

    一.官方方法 二.使用示例 1.场景图[图片上传失败...(image-7ceef2-1510195738500)...

  • IOS 通过经纬度计算两点的距离及坐标系转换

    通过经纬度计算两点的距离 坐标系转换 iOS开发中三大坐标系:地球坐标(WGS84) —— 国际标准,GPS标准从...

  • ios 地图坐标系转换

    ios 地图坐标系转换 https://segmentfault.com/a/1190000003023989 摘自网页

  • iOS开发之坐标系转换

    最近开发遇到了一些UI需要作坐标系的转换,如图 需要在原来添加标签按钮添加一个引导功能,添加标签按钮要与引导的添加...

  • iOS矩阵变换中的坐标系

    在一般情况下,UIkit 使用的是左上角为原点的坐标系,mac 开发中使用左下角的坐标系,但是我们在ios开发中,...

  • 2018-03-04

    常用坐标系统知识点 1.坐标系统之间的转换 (1)坐标系分类 不同参心坐标系之间的转换、不同地心坐标系之间的转换;...

  • iOS 时间戳、时间转换

    参考文档1:iOS时间类型转换和各种数据类型进行转换 参考文档2:iOS开发中的时间与日期(上) 转换工具:时间戳...

  • iOS 坐标系转换(convertPoint)

    直接移步简友的文章: iOS 坐标系转换(convertPoint)以及点在范围内的判断(pointInside)

  • ios-坐标系统

    转—ios-坐标系统(详解UIView的frame、bounds跟center属性 1、概要 翻开ios官方开发文...

  • iOS开发必会的坐标系探究[转载]

    iOS开发必会的坐标系探究https://zhuanlan.zhihu.com/p/49565437[https:...

网友评论

      本文标题:iOS开发中坐标系的转换

      本文链接:https://www.haomeiwen.com/subject/dsokdxtx.html