1、简单的两个view放到控制器的view里,其中blueView是redView的子控件
2、拖线到控制器里,打印各自的frame、转换坐标系后的frame
@interface ViewController ()
@property (weak, nonatomic) IBOutlet RedView *redView;
@property (weak, nonatomic) IBOutlet BlueView *blueView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"self.redView:%@,self.blueView:%@",NSStringFromCGRect(self.redView.frame),NSStringFromCGRect(self.blueView.frame));
CGRect newRectRed = [self.redView convertRect:self.redView.bounds toView:[UIApplication sharedApplication].keyWindow];
CGRect newRectRed2 = [self.redView convertRect:self.redView.bounds toView:self.view];
CGRect newRectBlue = [self.blueView convertRect:self.blueView.bounds toView:[UIApplication sharedApplication].keyWindow];
CGRect newRectBlue2 = [self.blueView.superview convertRect:self.blueView.bounds toView:self.view];
NSLog(@"newRectRed:%@,newRectBlue:%@",NSStringFromCGRect(newRectRed),NSStringFromCGRect(newRectBlue));
NSLog(@"newRectRed2:%@,newRectBlue2:%@",NSStringFromCGRect(newRectRed2),NSStringFromCGRect(newRectBlue2));
}
3、结果如下
疑问:为什么转到keywindow后的坐标和转到控制器的view的坐标不同呢?