【发布时间】:2019-09-03 20:15:48
【问题描述】:
我有一个 CollectionView 设置,里面有一个按钮,可以将单元格高度增加一个固定量。但是,当它这样做时,它会与下面的单元格重叠,这意味着下面的单元格不会向下移动以腾出空间。
这几天我一直在尝试解决这个问题,但我似乎无法让它发挥作用。
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
var colors = [UIColor.red,UIColor.blue]
@IBOutlet weak var col: UICollectionView!
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 2
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! cellCollectionViewCell
cell.frame.size.height = CGFloat(317 + cell.button.tag*45)
cell.backgroundColor = colors[indexPath.row]
return cell
}
@IBAction func increaseHeight(_ sender: Any) {
col.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
class cellCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var butt: UIButton!
@IBAction func incHeight(_ sender: UIButton) {
sender.tag = sender.tag + 1
}
}
【问题讨论】:
标签: swift xcode uicollectionview