美文网首页
坐标转换

坐标转换

作者: _iceCoke | 来源:发表于2017-08-10 15:00 被阅读0次
display_image.png
  • (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;
  • (CGRect)convertRect:(CGRect)rect fromView:(nullable UIView *)view;

Aview 在 Bview 上的 frame 转换到 Cview 坐标系下 frame (Aview 必需是 Bview 的 subview);

代码:
[Bview convertRect:Aview.frame toView:Cview];
[Aview convertRect:Aview.bounds toView:Cview];
[Cview convertRect:Aview.frame fromView:Bview];
[Cview convertRect:Bview.bounds fromeView:Bview];
- (void)viewDidLoad {
[super viewDidLoad];

NSLog(@"C : YELLOW --- %@", NSStringFromCGRect(self.yellowView.frame));
NSLog(@"B : RED ------ %@", NSStringFromCGRect(self.redView.frame));
NSLog(@"A : BLUE ----- %@", NSStringFromCGRect(self.blueView.frame));

} 

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
CGRect rect1 = [self.redView convertRect:self.yellowView.frame toView:self.blueView];
CGRect rect2 = [self.yellowView convertRect:self.yellowView.bounds toView:self.blueView];
CGRect rect3 = [self.blueView convertRect:self.yellowView.frame fromView:self.redView];
CGRect rect4 = [self.blueView convertRect:self.yellowView.bounds fromView:self.yellowView];
NSLog(@"\n\n");
NSLog(@"RESULT1 ------ %@", NSStringFromCGRect(rect1));
NSLog(@"RESULT2 ------ %@", NSStringFromCGRect(rect2));
NSLog(@"RESULT3 ------ %@", NSStringFromCGRect(rect3));
NSLog(@"RESULT4 ------ %@", NSStringFromCGRect(rect4));
}

打印结果:

C : YELLOW --- {{50, 50}, {135, 120}}
B : RED ------ {{40, 40}, {235, 220}}
A : BLUE ----- {{30, 30}, {315, 300}}

RESULT1 ------ {{90, 90}, {135, 120}}
RESULT2 ------ {{90, 90}, {135, 120}}
RESULT3 ------ {{90, 90}, {135, 120}}
RESULT4 ------ {{90, 90}, {135, 120}}

相关文章

  • 坐标转换

    http://blog.csdn.net/qq_35607510/article/details/53992602...

  • 坐标转换

    (CGRect)convertRect:(CGRect)rect toView:(nullable UIView ...

  • 坐标转换

    近两天需要把平面坐标转换为标准的WGS84后使用百度逆地址编码搜索出资料记录一下 类库 程序ProjNet4Geo...

  • 坐标转换

    1、将米转换成坐标度数 2、根据坐标点和半径将地图缩放到合适等级

  • 👈坐标转换

    / 将像素point由point所在视图转换到目标视图view中,返回在目标视图view中的像素值 -(CGPoi...

  • 坐标转换

  • 坐标转换

    世界空间 如何转换为 屏幕空间?

  • 坐标转换

    像素坐标转世界坐标的计算[https://www.jianshu.com/p/4566a1281066]

  • 坐标转换

    matlab计算过程 >> y1=[1.5035820007324219 2.1732330322265625 1...

  • 坐标转换

网友评论

      本文标题:坐标转换

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