swiftuiviewremovefromsuperview

removeFromSuperView() removes all of its subviews


I have a simple question regarding the method removeFromSuperview()

When for example I use it to remove a UIView, do I remove also all of this view subviews?

I tried to search online but didn't find anything explanatory at least to me.


Solution

  • Yes. Basically, that is what a subview is. What you do to a superview, qua view, you do its subviews. Move it, hide it, show it, transform it, change its alpha, whatever.

    Another way to think about it: what does it mean for a subview to have no superview in the interface? It means the subview is not in the interface. Well, you just took the superview out of the interface.

    And we can go further. The superview owns the subview. If you remove the superview, by default, it is destroyed. In that case, the subview is destroyed too; it has no owner any more.