TZStackView icon indicating copy to clipboard operation
TZStackView copied to clipboard

A way to safely remove a arranged subView

Open swapnil-sankla opened this issue 8 years ago • 2 comments

The current implementation of removing arrangedSubView is not great because even after removing arranged subView the view is still present. Remove arrangedSubView should work as expected.

A bonus would be if we can remove all the arrangedSubViews together. Some thing like -

@objc func removeAllArrangedSubViews() { for arrangedSubView in arrangedSubviews { removeArrangedSubview(arrangedSubView) arrangedSubView.removeFromSuperview() } updateConstraints() }

swapnil-sankla avatar Apr 06 '16 15:04 swapnil-sankla

The official UIStackView does not behave like that.

"This method removes the provided view from the stack’s arrangedSubviews array. The view’s position and size will no longer be managed by the stack view. However, this method does not remove the provided view from the stack’s subviews array; therefore, the view is still displayed as part of the view hierarchy."

andrebraga avatar Apr 07 '16 23:04 andrebraga

Interesting, at least the animation is still preserved!

    [stack removeArrangedSubview:subview];
    [subview removeFromSuperview];
    // Still animates out nicely!

warpling avatar Aug 20 '16 06:08 warpling