Ios 集合视图更改单元格大小
当选定单元格时,我试图更改Ios 集合视图更改单元格大小,ios,swift,uicollectionview,uicollectionviewcell,Ios,Swift,Uicollectionview,Uicollectionviewcell,当选定单元格时,我试图更改UICollectionView中单元格的高度 我设法改变了高度,但是,当我选择一个单元格时,其他单元格的y位置没有改变,导致所选单元格与其他单元格重叠 如果单元格高度被修改,如何通知其他单元格更改y位置 func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { if let detailsCell =
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)
}
这里的问题是,您单独处理单个单元格/项目,您应该使用autolayout来完成所有工作 定义代理上单元格/项目的大小:
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()
}
非常感谢。但是,在collect view delegate i count find
Heights for Row AtIndexPath
中,如果不能仅使用UItableView,则必须创建UICollectionViewFlowLayout,这需要更多的工作,如果可能的话,我确实建议迁移到UITableView。请检查此委托:collectionView:layout:SizeFormiteIndeXPath:我已经迁移到UITableView,效果非常好。。非常感谢。