我有一个带有以下配置的UIStackView,当我隐藏其第一个子视图时,我希望它的高度缩小而不是重新分配现有单元格的高度以填充或保留空白。
有没有办法做到这一点?目前,尽管隐藏了内容,但高度不会改变
let headerStackView = UIStackView()
headerStackView.backgroundColor = .clear
headerStackView.axis = .vertical
headerStackView.alignment = .fill
headerStackView.distribution = .equalSpacing
headerStackView.spacing = 0
headerStackView.isUserInteractionEnabled = true
headerStackView.translatesAutoresizingMaskIntoConstraints = false
约束
headerStackView.snp.makeConstraints { (make) -> Void in
make.leading.trailing.bottom.equalToSuperview()
make.top.equalTo(topView.snp.bottom)
}
隐藏子视图(与显示相反)
UIView.animate(withDuration: 0.35) { [weak self] in
headerStackView.arrangedSubviews.first.isHidden = true
headerStackView.arrangedSubviews.first.alpha = 0
self?.detailsHeaderView.headerStackView.layoutIfNeeded()
}