gpt4 book ai didi

ios - 如何对项目内不同组的多个图像进行动画处理?

转载 作者:行者123 更新时间:2023-11-30 11:29:02 34 4
gpt4 key购买 nike

大家。我的项目中有两个小组。让它们被称为“images1”和“images2”。我想对第一组中的所有图像进行动画处理,然后立即对 ViewController 中的第二组中的所有图像进行动画处理。首先,我创建图像数组,然后使用 UIView.animateKeyFrames 函数。不幸的是,我只能为第一组设置动画,当我尝试添加另一个关键帧来为另一组设置动画时,似乎没有任何效果。我还尝试将另一个关键帧放在“完成”所在的位置,但这会导致错误。我的代码:

import UIKit

class ViewController: UIViewController
{

var one: [UIImage] = []
var two: [UIImage] = []



override func viewDidLoad()
{
super.viewDidLoad()

one = createImageArray(total: 20, imagePrefix: "images1")
two = createImageArray(total: 20, imagePrefix: "images2")

UIView.animateKeyframes(withDuration: 3.0, delay: 0.0, options: [], animations: {
UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 3, animations: {
self.animatingImage.animationImages = self.one
self.animatingImage.animationDuration = 2
self.animatingImage.startAnimating()
})

UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 3, animations: {
self.animatingImage.animationImages = self.two
self.animatingImage.animationDuration = 2
self.animatingImage.startAnimating()
})

}, completion:{ _ in
print("end")
})
}

override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}

func createImageArray(total: Int, imagePrefix: String) -> [UIImage]
{
var imageArray: [UIImage] = []

for imageCount in 1...total
{
let imageName = "\(imagePrefix)\(imageCount).jpg"
let image = UIImage(named: "\(imageName)")!
imageArray.append(image)
}

return imageArray
}


@IBOutlet weak var animatingImage: UIImageView!

}

最佳答案

您可以将DispatchQueue.main.asyncAfterUIImage.animatedImage(with

一起使用

你可以这样使用它:

self.animatingImage = UIImage.animatedImage(with: one, duration: 1)

// animate after 1 sec
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self.animatingImage = UIImage.animatedImage(with: two, duration: 1)
}

关于ios - 如何对项目内不同组的多个图像进行动画处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50447020/

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