gpt4 book ai didi

ios - 动画 UICollectionView sizeForItemAtIndexPath (Swift)

转载 作者:搜寻专家 更新时间:2023-10-30 22:17:49 25 4
gpt4 key购买 nike

我想为调整 UICollectionViewCell 的大小设置动画。我已经编写了下面的代码,但不能在动画 block 中包含 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)

}

关于ios - 动画 UICollectionView sizeForItemAtIndexPath (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32144155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com