从主视图控制器的ViewDidAppear
UIView* parent = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
UIView* child1 = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 60, 60)];
UIView* child2 = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 20, 20)];
[parent setBackgroundColor:[UIColor redColor]];
[child1 setBackgroundColor:[UIColor blackColor]];
[child2 setBackgroundColor:[UIColor greenColor]];
[child1 addSubview:child2];
[parent addSubview:child1];
[self.view addSubview:parent];
NSLog(@"Absolute coordinates of child2: %@",NSStringFromCGRect([child2 convertRect:child2.frame toView:nil] ));
child2 的绝对点:{{150, 170}, {20, 20}}
我原以为原点是 (140,140, 20,20)。
为什么额外的 10X
和 30 的Y
?