gpt4 book ai didi

ios - 快速添加动画序列

转载 作者:行者123 更新时间:2023-11-30 13:11:44 28 4
gpt4 key购买 nike

Animation

我正在使用 Collection View ,并且我有以下代码来使用 CATransform3DRotate 对每个单元格进行动画处理,在执行时使用较小的延迟

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

guard let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as? RotationCollectionViewCell else {

fatalError("\(String(RotationCollectionViewCell)) not found")
}

self.addAnimationToCells(cell)

return cell
}

这是为单元格设置动画并创建延迟的代码

func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
self.delayTime += 0.05
print(delayTime, "WILL DISPLAY DELAY TIME")
}

private func addAnimationToCells(cell : UICollectionViewCell) {


let singleCell: UICollectionViewCell = cell
let layer: CALayer = singleCell.layer

layer.anchorPoint = CGPointMake(0.5, 0.0)

var transform = CATransform3DIdentity;
transform.m34 = 1.0 / 500.0;
transform = CATransform3DRotate(transform, CGFloat(90 * M_PI / 180), 1, 0, 0)
singleCell.layer.transform = transform

let start:CGFloat = 90
let end:CGFloat = 0

let rotationAnimation: CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation.x")
rotationAnimation.fromValue = start.degreesToRadians
rotationAnimation.toValue = end.degreesToRadians
rotationAnimation.duration = 0.5
rotationAnimation.repeatCount = 0
rotationAnimation.removedOnCompletion = false
rotationAnimation.fillMode = kCAFillModeForwards
rotationAnimation.delegate = CoreAnimationListener {
finished in

singleCell.layer.transform = CATransform3DIdentity

singleCell.layer.removeAllAnimations()
}

print(delayTime, "THIS IS MY DELAY TIME")

delay(delayTime){
cell.layer.addAnimation(rotationAnimation, forKey: "transform.rotation.x")
}
}

问题是,如果我滚动,就会出现空白区域。我认为是因为最后加载的单元格添加了累积延迟的动画,所以当我滚动时,它需要一些时间来制作动画。我不知道如何避免在加载时返回最后一个单元格添加时间延迟。请帮忙

最佳答案

正如@Beyowulf 评论的那样,我只需在 ViewDidAppear 中将delayTime重置为0

关于ios - 快速添加动画序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38645021/

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