UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
NSLog(@"window.f %@", NSStringFromCGRect(window.frame));
CGRect newFrame = [view convertRect:view.frame toView:window];
NSLog(@"原始:%@ 转换:%@", NSStringFromCGRect(view.frame), NSStringFromCGRect(newFrame));
window.f {{0, 0}, {320, 480}}
原始:{{85, 7}, {150, 30}} 转换:{{170, 34}, {150, 30}}
为什么 x 被翻倍了?
View 为灰色控件
如果将控件放到view 中
2016-03-07 02:39:25.662 微博2期[57203:938330] window.f {{0, 0}, {320,
480}} 2016-03-07 02:39:25.662 微博2期[57203:938330] 原始:{{20, 60}, {40,
20}} 转换:{{40, 184}, {40, 20}}
得到以上数据。。。184 - 64 正好 120,也就是说x * 2, y * 2 了
将控件添加到一个视图中,相对于视图转换(这个比较难说明白,简单说就是排除了各种bar的干扰)结果直接x y 都双倍了。。。
Two correct ways of writing
The caller of convertRect has a misunderstanding. It should be the reference system view of the control that needs to be converted, not itself.
[view convertRect:view.frame toView:window]
->[view convertRect:view.frame toView:nil]
If it is changed to this, there will be no phenomenon described by the subject of the question.