1链患、簡(jiǎn)單的兩個(gè)view放到控制器的view里巧鸭,其中blueView是redView的子控件
2、拖線到控制器里麻捻,打印各自的frame纲仍、轉(zhuǎn)換坐標(biāo)系后的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、結(jié)果如下
疑問(wèn):為什么轉(zhuǎn)到keywindow后的坐標(biāo)和轉(zhuǎn)到控制器的view的坐標(biāo)不同呢贸毕?