问题描述
在removeArrangedSubview中:
In removeArrangedSubview:
在organizedSubview中:
In arrangedSubview:
从这些看来,仅调用removeFromSuperview就足以删除一个子视图,而我一直在使用它而没有问题.我还通过调用removeFromSuperview时记录了rangingSubviews数组的计数来确认此行为.
From these, it seems that calling just removeFromSuperview is enough to remove a subview and I've been using it like that without problems. I also confirmed the behavior by logging the count of the arrangedSubviews array when removeFromSuperview is called.
但是,这里有许多有关S/O的教程和评论,请说两者都称呼.是否有一个原因?还是人们只是这样做,因为文档中是这样说的?
A lot of tutorials and comments here on S/O however, say to call both. Is there a reason for this? Or do people just do it because the documentation says so?
推荐答案
不,只需调用 subview.removeFromSuperview()
/* Removes a subview from the list of arranged subviews without removing it as
a subview of the receiver.
To remove the view as a subview, send it -removeFromSuperview as usual;
the relevant UIStackView will remove it from its arrangedSubviews list
automatically.
*/
open func removeArrangedSubview(_ view: UIView)
这篇关于UIStackView:是否真的需要同时调用removeFromSuperView和removeArrangedSubview来删除子视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!