【发布时间】:2014-10-29 12:36:34
【问题描述】:
我有collectionView,每个单元格中都有图像。
我想在点击单元格时查看完整图像。
我知道这可以通过 selectItemAtIndexPath 方法完成,并且我需要对选定的单元格做一些事情:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
{
println("Row: \(indexPath.row) is selected")
var cell:UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)!
}
我在 objc 中看到了很多代码示例,例如 here,但我在 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)
}
我得到的错误是在块行的开头:
Cannot convert the expression's type '() -> () -> $T0' to type '() -> () -> $T0'
我认为它仍然与定义(弱)单元格有关。
【问题讨论】:
标签: swift uiimageview uicollectionview