我正在尝试UICollectionView
选择单元格时更改单元格的高度。
我设法更改了高度,但是,当我选择一个单元格y
时,其他单元格的位置不会改变,从而导致所选单元格与其他单元格重叠。
修改单元格高度后,如何告诉其他单元格更改y位置?
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
if let detailsCell = collectionView.cellForItemAtIndexPath(indexPath) as? UserDetailsCell {
UIView.animateWithDuration(0.5, delay: 0, options: .TransitionCurlUp, animations: {
detailsCell.frame.size.height = 300
}, completion: nil)
}
print(indexPath.row)
}
这里的问题是您要单独处理单个单元格/项目,您应该只使用自动布局完成所有工作。
在委托上定义单元格/项目的大小:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if let selectedRows = tableView.indexPathsForSelectedRows {
if selectedRows.contains(indexPath) {
return 300
}
}
return 40
}
在选择中,您只需要对版面进行更新即可。
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.beginUpdates()
tableView.endUpdates()
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句