UIStackView : Is it really necessary to call both removeFromSuperView and removeArrangedSubview to remove a subview?

后端 未结 8 794
遥遥无期
遥遥无期 2021-02-02 05:04

From the UIStackView Class Reference

In removeArrangedSubview:

To prevent the view from appearing on screen after calling the stack’s removeArrang

相关标签:
8条回答
  • 2021-02-02 05:48

    In iOS 12.0, You need to use

    stackView.arrangedSubviews[index].removeFromSuperview()
    

    If you use removeArrangedSubview, there is a bug where the view at the specified index removed, but the view I want to clear appears at CGPoint(x: 0, y: 0).

    Hope this help someone.

    0 讨论(0)
  • 2021-02-02 05:51

    You're right, just the call to removeFromSuperview is sufficient to have the view fully removed.

    I suspect the reason for people putting both is because they run across the removeArrangedSubview documentation which seems to say both are needed. (And indeed, they are, if you call removeArrangedSubview and want the view really gone.)

    The additional doc in arrangedSubviews is not seen by so many, so they don't realize removeArrangedSubview is, in this case, optional.

    0 讨论(0)
提交回复
热议问题