如何将子视图添加到视图层次结构的底部
How to addSubview to the bottom of view hierarchy
我想将我以编程方式添加的 mapView 添加到层次结构视图的底部,因为我已经预先在故事板中绘制了一些元素。
所以,在我调用方法之后:
[self.view addSubview:self.map];
如何将它放在视图层次结构的底部?!
"This method moves the specified view to the beginning of the array of views in the subviews property."
[self.view sendSubviewToBack:yourView];
直接放在那里就可以了。
[self.view insertSubview:_map atIndex:0];
罗伯特和 rcat24 的回答确实有效。
或者,
您可以使用"zPosition"
subViewToBeOnTop.layer.zPosition=1.0;
subViewToBeOnBottom.layer.zPosition=.9;
1 为最高,0 为最低。
Swift 3
Swift 4
view.insertSubview(view, at: 0)
我想将我以编程方式添加的 mapView 添加到层次结构视图的底部,因为我已经预先在故事板中绘制了一些元素。
所以,在我调用方法之后:
[self.view addSubview:self.map];
如何将它放在视图层次结构的底部?!
"This method moves the specified view to the beginning of the array of views in the subviews property."
[self.view sendSubviewToBack:yourView];
直接放在那里就可以了。
[self.view insertSubview:_map atIndex:0];
罗伯特和 rcat24 的回答确实有效。 或者,
您可以使用"zPosition"
subViewToBeOnTop.layer.zPosition=1.0;
subViewToBeOnBottom.layer.zPosition=.9;
1 为最高,0 为最低。
Swift 3
Swift 4
view.insertSubview(view, at: 0)