如何设置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;
兄弟视图在子视图中排在前面
数组。所以最顶层的视图将是:
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屋!