使用Swift在selectItemAtIndexPath中显示图像

使用Swift在selectItemAtIndexPath中显示图像,swift,uiimageview,uicollectionview,Swift,Uiimageview,Uicollectionview,我有collectionView,每个单元格中都有图像。 我想在点击手机时看到完整的图像 我知道这可以通过selectItemAtIndexPath方法完成,我需要对所选单元格执行一些操作: func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { println("Row: \(indexPath.row) is selected")

我有
collectionView
,每个单元格中都有图像。 我想在点击手机时看到完整的图像

我知道这可以通过
selectItemAtIndexPath
方法完成,我需要对所选单元格执行一些操作:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
{
   println("Row: \(indexPath.row) is selected")

   var cell:UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)!
}
我在objc中看到了很多代码示例,比如,但在Swift中我无法理解

先谢谢你


更新:

到目前为止,我的代码是:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
{   
    collectionView.collectionViewLayout.invalidateLayout()
    let cell = collectionView.cellForItemAtIndexPath(indexPath)
    let animateChangeWidth = { [weak cell] in
        let frame:CGRect = cell.frame
        frame.size = cell.intrinsicContentSize()
        cell.frame = frame
    }
    UIView.transitionWithView(cell, duration: 0.7, options: UIViewAnimationOptions.CurveLinear, animations: animateChangeWidth, completion: nil)
}
我得到的错误在块行的开头:

无法将表达式的类型“()->()->$T0”转换为类型“()->()->$T0”


我认为它仍然与定义(弱)单元有关。

与链接的帖子类似,先使布局无效,然后设置一个闭包作为动画块

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
{
    collectionView.collectionViewLayout.invalidateLayout()
    let cell = collectionView.cellForItemAtIndexPath(indexPath)!
    let animateChangeWidth: ()-> Void  = {[weak cell] in
        if let validCell = cell {
            var frame = validCell.frame
            frame.size = validCell.viewWithTag(100)!.intrinsicContentSize()
            validCell.frame = frame
        }

    }
    UIView.transitionWithView(cell, duration: 0.7, options: UIViewAnimationOptions.CurveLinear, animations: animateChangeWidth, completion: nil)
}

感谢您的快速反应,我不明白您对
弱电池的意思?你还在用
在一个闭包内?
[弱单元]
是一个闭包,以避免一个保留周期。我把它放在那里是因为另一个人使用了对
单元格的弱引用,所以我想我们最好在这里也使用它。(编辑掉分号,不需要,复制粘贴错误)仍然无法在@JMFR工作。它给了我一个奇怪的错误,告诉我它无法转换表达式的类型。请参阅更新。这个问题似乎不在我的联盟Xcode范围内。您可以尝试从捕获列表中删除。是否删除
部分中的
[弱单元格]?或者为我们的闭包声明一个类型,应该是
()->Void
我确实让代码工作并启动了动画,但我也不是集合视图专家。您可以在一个简单的集合视图中签出代码,该视图中的图像在被选中时会缩放。问题在于,当所选图像缩放时,集合中的其他视图不会移动。如果您需要更多帮助,请随时联系我们。