ios - 如何在按钮单击时更改 UICollectionView 高度
问题描述
当我单击按钮时,我正在尝试更改集合视图和视图的高度。但是当我单击按钮时,视图的高度会发生变化,但集合视图的高度不会发生变化。
这是我的代码:
@IBAction func button(_ sender: Any) {
UIView.animate(withDuration: 1, animations: {
self.backView.frame.size.height -= 160
self.collectionView.frame.size.height -= 160
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseOut,
animations: self.view.layoutIfNeeded, completion: nil)
}, completion: nil)
}
我还能做些什么来调整集合视图的大小?
解决方案
如果您在该集合视图上使用了约束,则需要更改高度约束的常量,而不是其框架。像这样:
@IBAction func button(_ sender: Any) {
UIView.animate(withDuration: 1, animations: {
self.backView.frame.size.height -= 160
self.collectionViewHeightConstraint.constant = <value>
self.view.layoutIfNeeded()
}, completion: nil)
}
推荐阅读
- postgresql - Hyperledger Iroha 没有连接到 postgres 数据库?
- tensorflow - 我可以在云和边缘设备上分发训练和推理 DNN 架构吗?
- php - 显示来自 MySQL 的未找到数据
- javascript - 在 Node/Mongoose 中查找用户列表并进行迭代
- go - 阻止 godog 解析 Scenario Outline 示例数据表行
- javascript - 将 new 作为对象推送到数组
- python - 我需要使用模拟吗?
- jquery - 具有定制设计的光滑滑块
- python - 在 TensorFlow 中恢复保存的神经网络
- c# - 转换列表