UICollectionviewCell 动画 [英] UICollectionviewCell Animations
本文介绍了UICollectionviewCell 动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要动画集合视图单元格,动画应该是这样的:
I want to animate the collectionview cells,the animations should be like this:
第一个单元格出现,然后经过一段时间的延迟第二个单元格会出现一些动画,这对于所有的单元格都会这样继续.
First Cell Appear and then after some delay second cell will appear with some animations,this will go on like this for all the cells.
如何实现这一目标?
推荐答案
这里的另一个解决方案是使用 willDisplayCell:forIndexPath
委托
The other solution here is using willDisplayCell:forIndexPath
delegate
这是我如何做的示例.
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
if (!loadedIdx.contains(indexPath.row)) {
let cellContent = cell
let rotationAngleDegrees : Double = -30
let rotationAngleRadians = rotationAngleDegrees * (M_PI/180)
let offsetPositioning = CGPoint(x: collectionView.bounds.size.width, y: -20)
var transform = CATransform3DIdentity
transform = CATransform3DRotate(transform, CGFloat(rotationAngleRadians), -50, 0, 1)
transform = CATransform3DTranslate(transform, offsetPositioning.x, offsetPositioning.y, -50)
cellContent.layer.transform = transform
cellContent.layer.opacity = 0.2
let delay = 0.06 * Double(indexPath.row)
UIView.animateWithDuration(0.8, delay:delay , usingSpringWithDamping: 0.8, initialSpringVelocity: 0.5, options: .CurveEaseIn, animations: { () -> Void in
cellContent.layer.transform = CATransform3DIdentity
cellContent.layer.opacity = 1
}) { (Bool) -> Void in
}
loadedIdx.append(indexPath.row)
}
}
loadedIdx 是一个数组,用于将单元格标记为已加载(下次出现时不会动画)
The loadedIdx is an array to mark cell as loaded ( not animate in the next time appear)
这篇关于UICollectionviewCell 动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文