如何设置 iPhone UIView z 索引? [英] How to set iPhone UIView z index?
问题描述
我想将一个视图移动到另一个视图的顶部,我如何知道视图的 z 索引,以及如何移动到顶部?
I want to move one view on top of another, how can I know the z index of the view, and how to move on to top?
推荐答案
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.
这篇关于如何设置 iPhone UIView z 索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!