![](/img/trans.png)
[英]Swift : UICollectionView Cell can not update frame when implement sizeForItemAtIndexPath
[英]Animate UICollectionView sizeForItemAtIndexPath (Swift)
我想动画调整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
})
}
如果要进行动画处理,请调用以下方法:
self.collectionView.performBatchUpdates(updates: (() -> Void), completion:((Bool) -> Void)?)
更具体地说,您还应该处理方向更改,如下所示,
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation)
{
self.collectionView.performBatchUpdates(nil, completion: nil)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.