Resizing UIStackView when hiding a subview?

北城余情 提交于 2019-12-11 15:25:52

问题


I have a UIStackView with the config below, when i hide its first subview i want it to shrink in height rather than redistributing the height of the existing cells to fill or leaving white space.

Is there a way to achieve this? as currently it wont change in height despite hiding its contents

 let headerStackView = UIStackView()
    headerStackView.backgroundColor = .clear
    headerStackView.axis = .vertical
    headerStackView.alignment = .fill
    headerStackView.distribution = .equalSpacing
    headerStackView.spacing = 0
    headerStackView.isUserInteractionEnabled = true
    headerStackView.translatesAutoresizingMaskIntoConstraints = false

Constraints

    headerStackView.snp.makeConstraints { (make) -> Void in
       make.leading.trailing.bottom.equalToSuperview()
       make.top.equalTo(topView.snp.bottom)
    }

Hiding of subview (opposite for showing)

            UIView.animate(withDuration: 0.35) { [weak self] in
            headerStackView.arrangedSubviews.first.isHidden = true
            headerStackView.arrangedSubviews.first.alpha = 0
            self?.detailsHeaderView.headerStackView.layoutIfNeeded()
        }

来源:https://stackoverflow.com/questions/56839218/resizing-uistackview-when-hiding-a-subview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!