ios开发-坐标系转换
2015-09-16 21:28
639 查看
#import "ViewController.h" @interface ViewController () @property(nonatomic,weak)UIView *blue; @property(nonatomic,weak)UIView *red; @property(nonatomic,weak)UIView *yellow; @property(nonatomic,weak)UIView *purple; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //蓝色 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); [self.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 yellowColor]; purple.frame = CGRectMake(150, 350, 100, 100); [self.view addSubview:purple]; self.yellow = purple; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //原点变了相当于坐标系平移 // CGRect newRect = [self.red convertRect:CGRectMake(50, 50, 50, 50) fromView:self.blue]; // NSLog(@"%@",NSStringFromCGRect(newRect)); // // NSLog(@"%@",NSStringFromCGRect(self.yellow.bounds)); // // NSLog(@"%@",NSStringFromCGRect(self.yellow.frame)); //黄色在蓝色中的位置 //CGRect newRect = [self.yellow convertRect:CGRectMake(0, 0, 50, 50) toView:self.blue]; // CGRect newRect = [self.yellow convertRect:self.yellow.bounds toView:self.blue]; //计算self.yellow 在其他控件中的位置 // CGRect newRect1 = [self.yellow convertRect:self.yellow.bounds fromView:self.blue]; // CGRect newRect = [self.yellow.superview convertRect:self.yellow.frame fromView:self.blue ]; // //黄色在紫色中的位置 // CGRect newRect = [self.yellow.superview convertRect:self.yellow.frame toView:self.purple]; //计算self.red 在主窗口中的位置和尺寸(nil 代表屏幕) CGRect newRect = [self.red convertRect:self.red.bounds toView:nil]; NSLog(@"%@",NSStringFromCGRect(newRect)); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- ios开发-新浪微博12-(标题按钮的箭头上下翻转)
- ios开发-新浪微博11-(自定义tabbar)
- iOS 窗口抖动效果代码及解释
- ios动画
- ios开发-新浪微博10-(下拉菜单的二次封装 完整版)
- ios开发-新浪微博-09(下拉菜单封装一)
- wxhl iOS bj 49 张浩 学习心得体会连载 第10章
- ios开发-新浪微博08-下拉菜单的基本实现
- ios-新浪微博开发07-自定义搜索框
- 猫猫学iOS 之微博项目实战(10)微博cell中图片的显示以及各种填充模式简介
- iOS现成的引导页面的实现:纯代码
- ios7.1以后,iphone上隐藏应用图标的方法
- IOS afn三方上传图片
- IOS rumen
- iOS开发 -- WebSocket 通信(一)
- iOS中FMDB简介
- IOS-六种手势的简单使用
- IOS开发学习的思维导图
- iOS6 创建全局的pch文件
- iOS中几种数据永久存储方式