Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 集合视图更改单元格大小_Ios_Swift_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

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,效果非常好。。非常感谢。