UIView. How do I place a subview behind it's parent superview

时光毁灭记忆、已成空白 提交于 2020-01-03 17:26:35

问题


I'm doing a bit of UIView wrangling and am stuck. It is straightforward changing the "z" order of sibling subviews. [mySuperview sendSubviewToBack:mySubview] places mySubview behind all it's siblings.

But how do I place a subview behind it's parent?

Thanks, Doug


回答1:


You may want to put both into a container view, so that you can properly place one behind the other without affecting a superview not really meant to hold arbitrary views (although that will probably work just fine).




回答2:


You can't as far as I know. You'll have to remove it from the parent then add it to the parent's parent's subviews.

UIView *parent = view.superview;
[view removeFromSuperview];

/* Adjust frame to realign under parent view */

[parent.superview addSubview:view];


来源:https://stackoverflow.com/questions/1507174/uiview-how-do-i-place-a-subview-behind-its-parent-superview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!