坐标系的转换
来源:互联网 发布:有试衣间的淘宝店铺 编辑:程序博客网 时间:2024/06/06 18:15
转换坐标系就是本来中间那个家伙是以左边那个家伙为坐标系的,现在变为以右边那个家伙为坐标系,它的坐标变为多少,就是中间那个控件以右边那个控件为坐标的位置(最后的结果就是两个坐标系的x和y值之间的差别高度和宽度不变)
// 蓝色
UIView *blue = [[UIView alloc] init];
blue.backgroundColor = [UIColor blueColor];
blue.frame = CGRectMake(0,50,200,200);
[self.view addSubview:blue];
self.blue = blue;
// 红色
UIView *red = [[UIView alloc] init];
red.backgroundColor = [UIColor redColor];
red.frame = CGRectMake(50,60,100,100);
[blue addSubview:red];
self.red = red;
// 黄色
UIView *yellow = [[UIView alloc] init];
yellow.backgroundColor = [UIColor yellowColor];
yellow.frame = CGRectMake(10,10,50,50);
[red addSubview:yellow];
self.yellow = yellow;
// 紫色
UIView *purple = [[UIView alloc] init];
purple.backgroundColor = [UIColor purpleColor];
purple.frame = CGRectMake(150,350,100,100);
[self.view addSubview:purple];
self.purple = purple;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// NSLog(@"%@", NSStringFromCGRect(self.yellow.bounds));
// NSLog(@"%@", NSStringFromCGRect(self.yellow.frame));
// 计算self.yellow在self.blue中的位置和尺寸
// CGRect newRect = [self.yellow convertRect:self.yellow.bounds toView:self.blue];{60,70,50,50}
// 计算self.yellow在self.purple中的位置和尺寸
// CGRect newRect = [self.yellow.superview convertRect:self.yellow.frame toView:self.purple];{60,70,50,50}
// 计算self.red在self.yellow中的位置和尺寸
// CGRect newRect = [self.red convertRect:self.red.bounds toView:self.yellow];
// 计算self.red在self.yellow中的位置和尺寸
// CGRect newRect = [self.yellow convertRect:self.red.bounds fromView:self.red];
// 计算self.red在屏幕中的位置和尺寸(nil代表屏幕)
CGRect newRect = [self.red convertRect:self.red.bounds toView:nil];
NSLog(@"%@", NSStringFromCGRect(newRect));
}
- 坐标系的转换
- 平面的坐标系转换
- 坐标系的转换
- ios 坐标系的转换
- 坐标系的转换
- 转换控件的坐标系
- quat的坐标系转换
- iOS坐标系的转换
- 坐标系的转换
- 二维坐标系的转换
- 坐标系之间的转换
- cocos2d-x的坐标系转换
- 两个坐标系间的转换
- openGL 坐标系的互相转换
- iOS 地图坐标系的转换
- 经验之谈—坐标系的转换
- OpenGL坐标系之间的转换
- 几大坐标系的转换
- struct class
- 线程详解
- 如何让孩子爱上设计模式 ——16.迭代器模式(Iterator Pattern)
- (3)FPQuant JHipster_使用AngularJS1
- 关于操作系统的几个重要概念(五)
- 坐标系的转换
- 图文并茂教你用iphone发短信控制自己的mac锁屏、关机等操作
- c++基础:如何string类型转换为int类型
- automaticallyAdjustsScrollViewInsets属性
- C 语言高效编程与代码优化
- ViewPager的使用方法
- 7层登录--反射的神奇所在
- Redis主从复制
- 前端性能优化总结