UICollectionView中的sizeForItemAtIndexPath动画(Swift)

6

我想要为UICollectionViewCell的调整大小添加动画效果。我已经编写了下面的代码,但无法在动画块内使用return行。有什么想法吗?

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

    var newSize = CGSize(width: (self.view.frame.width), height: 0)


    UIView.animateWithDuration(2.0, animations: { () -> Void in
        return newSize
    })

}
1个回答

2

如果您想进行动画操作,请调用以下方法:

self.collectionView.performBatchUpdates(updates: (() -> Void), completion:((Bool) -> Void)?)

更具体地说,您还应该处理方向更改,如下所示:
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation)
{
    self.collectionView.performBatchUpdates(nil, completion: nil)

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接