更新时间:2023-11-10 10:02:52
UIView
兄弟姐妹按添加到其父视图的顺序堆叠.UIView
层次结构方法和属性用于管理视图顺序.在 UIView.h 中:
UIView
siblings are stacked in the order in which they are added to their superview. The UIView
hierarchy methods and properties are there to manage view order. In UIView.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
数组中从前到后排序.所以最上面的视图将是:
The sibling views are ordered back to front in the subviews
array. So the topmost view will be:
[parentView.subviews lastObject];
底部视图将是:
[parentView.subviews objectAtIndex:0];
就像 Kolin Krewinkel 所说的那样,[parentView BringSubviewToFront:view]
会将视图带到顶部,但只有当视图在层次结构中都是兄弟时才会出现这种情况.
Like Kolin Krewinkel said, [parentView bringSubviewToFront:view]
will bring the view to the top, but this is only the case if the views are all siblings in the hierarchy.