UIView
个同级按其添加到superview的顺序堆叠.UIView
个层次 struct 方法和属性用于管理视图顺序.在我看来.h:
@property(nonatomic,readonly) UIView *superview;
@property(nonatomic,readonly,copy) NSArray *subviews;
- (void)removeFromSuperview;
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;
- (void)addSubview:(UIView *)view;
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
- (void)bringSubviewToFront:(UIView *)view;
- (void)sendSubviewToBack:(UIView *)view;
同级视图在subviews
数组中从后到前排序.因此,最上面的视图将是:
[parentView.subviews lastObject];
底部视图为:
[parentView.subviews objectAtIndex:0];
正如Kolin Krevinkel所说,[parentView bringSubviewToFront:view]
会将视图置于顶部,但只有当视图都是层次 struct 中的同级视图时,情况才会如此.