[cell insertSubview:myView belowSubview:cell.contentView];
[whiteColorView addSubview:redColorView];
[whiteColorView addSubview:greenColorView];
[whiteColorView insertSubview:blueColorView belowSubview:greenColorView];
显示层级从下至上为:white—>red—>blue—>green
执行如下代码:
[whiteColorView addSubview:redColorView];
[redColorView addSubview:greenColorView];
[whiteColorView insertSubview:blueColorView belowSubview:greenColorView];
显示层级从下至上为:white—>red—>green—>blue
以上两段代码在iOS6和iOS7上执行的效果相同。
(实验2)UITableViewCell的层级研究
在tableView:cellForRowAtIndexPath:方法中执行如下代码:
NSLog(@"%@", cell);
NSLog(@"%@", cell.superview);
NSLog(@"%@", cell.contentView);
NSLog(@"%@", cell.contentView.superview);
NSLog(@"%@", cell.contentView.superview.superview);
2014-01-17 02:34:22.917 InsertViewDemo[76500:907]
2014-01-17 02:34:22.919 InsertViewDemo[76500:907] (null)
2014-01-17 02:34:22.920 InsertViewDemo[76500:907]
2014-01-17 02:34:22.921 InsertViewDemo[76500:907]
2014-01-17 02:26:20.561 InsertViewDemo[76452:70b]
2014-01-17 02:26:20.562 InsertViewDemo[76452:70b] (null)
2014-01-17 02:26:20.563 InsertViewDemo[76452:70b]
2014-01-17 02:26:20.563 InsertViewDemo[76452:70b]
[cell insertSubview:myView belowSubview:cell.contentView];
[cell.contentView.superview insertSubview:myView belowSubview:cell.contentView];