0

.

你好,

在界面生成器中,设置项目的顺序非常容易,就像在图层中一样,通过将它们一层一层地拖动。

我没有成功在代码中复制它。

我需要添加什么线才能产生类似的效果?

干杯

4

2 回答 2

2

引用另一篇文章,有很多有用的方法可以达到这个目的:

@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;

他们的名字是相当不言自明的。您特别感兴趣的可能是 insertSubview:AtIndex、insertSubview:belowSubview(或更高版本)以及bringSubviewToFront 和sendSubviewToBack。这些将允许您构建视图,而无需以任何特定顺序添加它们。

于 2012-05-27T04:45:19.310 回答
0

只需以相反的顺序子查看它们(如果你想在顶部,子视图最后)。还有一些功能可以在参考子视图之前或之后插入子视图。

于 2012-05-27T04:33:41.777 回答