-1

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.

StackGU
  • 868
  • 9
  • 22

1 Answers1

2

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    Really useful answer, I have a question tho, why when I embed an AVPlayer inside a UIView and then remove that UIView, I still have memory occupied by that avplayer? – StackGU Oct 23 '20 at 13:47
  • 1
    AVPlayer is not a view, so you cannot "embed" it inside a UIView, so your new question makes no sense. Anyway, that is not what you asked. I'm here to answer the question you actually asked, not some other question that you may have been hiding. – matt Oct 23 '20 at 14:25
  • This is not something I was hiding, just a curiosity and I would have appreciated If you knew how to answer, anyway I'm gonna accept your answer because it was complete – StackGU Oct 23 '20 at 14:40
  • 3
    Well I _do_ know how to answer and I answered it. An AVPlayer is not a view, and removing a UIView would not change anything about an AVPlayer. They live in totally unrelated conceptual worlds. – matt Oct 23 '20 at 14:41
  • 1
    I think @StackGU meant AVPlayerLayer – aheze Oct 23 '20 at 16:01
  • 1
    @aheze Maybe. But learning to say what you mean is an important part of using Stack Overflow effectively. – matt Oct 23 '20 at 16:23