gpt4 book ai didi

ios - 将 UIView subview 附加到父 View

转载 作者:行者123 更新时间:2023-11-29 04:23:26 25 4
gpt4 key购买 nike

我正在尝试在 iPad 应用程序中使用 UIView 做一些有点棘手的事情。以这个 View 结构为例:

View 1 > View 2 > View 3

请注意,3 个 View 的大小相同,并且都显示在彼此的顶部。 View 1 是 View 2 的父级, View 2 是 View 3 的父级。用户当前看到的 View 3 位于顶部。

我想删除 View 2 并将 View 3 及其所有 subview 附加到 View 1 上——而不更改当前显示。基本上,删除后台的 View 2。我无法使用 removeFromSuperview ,因为如果我这样做,它也会删除 View 3(这是用户当前正在查看的内容)。

我意识到让所有 3 个 View 成为另一个父 View 的 subview 可能更有意义,这样我就可以随意 removeFromSuperview ——但是我真的只是好奇是否有人做过像我上面描述的那样的工作。

最佳答案

如果我正确理解你想要做什么,这应该有效:

[view1 addSubview:view3];
[view2 removeFromSuperview];

来自UIView class ref :

Views can have only one superview. If view already has a superview and that view is not the receiver, this method removes the previous superview before making the receiver its new superview.

关于ios - 将 UIView subview 附加到父 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12669475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com