ios - 如何更改集合视图中单个单元格的大小?我想获取滑块的值并使用该值来调整单元格的大小
问题描述
到目前为止,我已经在每个单元格中创建了一个带有标签的集合视图。我有一个将新单元格附加到数组的按钮。我什至可以让单元格根据滑块的值平均改变高度。但是,我不确定如何更改集合视图中仅一个单元格的大小。任何人都知道如何做到这一点?我还没有看到它的答案。
如有必要,我可以发布我的代码
编辑:由于要求,这里是代码:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return visualArray.count
}
func collectionView(_: UICollectionView, layout: UICollectionViewLayout, sizeForItemAt: IndexPath) -> CGSize {
return CGSize(width: self.collectionThing.frame.height / 6 * 5, height: CGFloat(sliderSlider.value * 4))
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "VisualCollectionViewCell", for: indexPath) as! VisualCollectionViewCell
cell.visualLabel.text = visualArray[indexPath.row]
return cell
}
解决方案
假设您使用的UICollectionViewDelegateFlowLayout
是默认布局,您可以使用委托方法func collectionView(UICollectionView, layout: UICollectionViewLayout, sizeForItemAt: IndexPath) -> CGSize
为该特定单元格返回新大小。
collectionView.performBatchUpdates
我相信如果您使用空闭包调用,您可以触发动画重新布局,一旦单元格的大小发生变化,您应该这样做。
如果这不起作用,您将需要创建一个自定义集合视图布局,网上有一些关于如何做到这一点的教程。
推荐阅读
- pos - 如何使用 Microsoft POS 打印机画线
- postgresql - Postgres 字符串操作
- movesense - 无法从 AdbBridge 配置 LSM6DS3
- java - 如何将hibernate xml转换为java注解
- c# - 如何在 C# 中的 WPF 应用程序中解锁 Windows 屏幕?
- python - 如何使用枢轴重塑我的熊猫数据框?
- google-cloud-platform - 对 Google 管理的 SSL 证书进行故障排除
- python - 我正在尝试使用 pandas 导入 CSV 文件,但出现错误。(看图片)
- r - 如何根据另一个变量重新排序 X 轴日期
- flutter - 错误:无法在“ServicesBinding?”上访问属性“defaultBinaryMessenger” 因为它可能为空