[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] <Cell: 0x754d680; baseClass = UITableViewCell; frame = (0 0; 320 100); autoresize = RM+BM; layer = <CALayer: 0x754d800>>
2014-01-17 02:34:22.919 InsertViewDemo[76500:907] (null)
2014-01-17 02:34:22.920 InsertViewDemo[76500:907] <UITableViewCellContentView: 0x754d950; frame = (0 0; 320 100); clipsToBounds = YES; opaque = NO; gestureRecognizers = <NSArray: 0x754e9b0>; layer = <CALayer: 0x754d9e0>>
2014-01-17 02:34:22.921 InsertViewDemo[76500:907] <Cell: 0x754d680; baseClass = UITableViewCell; frame = (0 0; 320 100); autoresize = RM+BM; layer = <CALayer: 0x754d800>>
2014-01-17 02:26:20.561 InsertViewDemo[76452:70b] <Cell: 0x8a10710; baseClass = UITableViewCell; frame = (0 0; 320 100); autoresize = RM+BM; layer = <CALayer: 0x8a10900>>
2014-01-17 02:26:20.562 InsertViewDemo[76452:70b] (null)
2014-01-17 02:26:20.563 InsertViewDemo[76452:70b] <UITableViewCellContentView: 0x8a10af0; frame = (0 0; 320 100); clipsToBounds = YES; opaque = NO; gestureRecognizers = <NSArray: 0x8a12270>; layer = <CALayer: 0x8a10ba0>>
2014-01-17 02:26:20.563 InsertViewDemo[76452:70b] <UITableViewCellScrollView: 0x8a113a0; frame = (0 0; 320 100); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x8a11950>; layer = <CALayer: 0x8a115d0>; contentOffset: {0, 0}>
[cell insertSubview:myView belowSubview:cell.contentView];
[cell.contentView.superview insertSubview:myView belowSubview:cell.contentView];