在界面生成器中,有一些布局选项可以将任何元素发送到后面或发送到前面,例如UIButton
, UIImage
, UILabel
etc...
现在,我想在运行时以编程方式执行相同的操作。
有没有简单的方法可以做到这一点?
我不想创建不同的视图,只需更新 z 轴。
有多种方法UIView
允许您修改视图层次结构。
- bringSubviewToFront: https://developer.apple.com/documentation/uikit/uiview/1622541-bringsubview
- sendSubviewToBack: https://developer.apple.com/documentation/uikit/uiview/1622618-sendsubview
- insertSubview:atIndex: https://developer.apple.com/documentation/uikit/uiview/1622538-insertsubview
- insertSubview:aboveSubview: https://developer.apple.com/documentation/uikit/uiview/1622570-insertsubview
- insertSubview:belowSubview: https://developer.apple.com/documentation/uikit/uiview/1622598-insertsubview
- exchangeSubviewAtIndex:withSubviewAtIndex: https://developer.apple.com/documentation/uikit/uiview/1622448-exchangesubview
由于您的视图已经插入到您的超级视图中,因此您可以轻松调用bringSubviewToFront:
按您喜欢的顺序为每个视图一次。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)