gpt4 book ai didi

ios - 动画图标变化

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

我正在开发我的第一个应用程序,它是一个数学谜语应用程序。玩家可以获得一个提示,该提示将揭示其中一个变量 - 它基本上是用一张图像替换另一张图像。有时我要替换多个图像,因此我使用一个循环来替换所有图像。我希望旧图像褪色并被新图像取代,这就是答案。另外,我希望它们一个接一个地淡出,这意味着一个图像替换动画与下一个图像替换动画之间会有一小段延迟。

func changeHintIcons () {

var labelsArr = [[firstEquationFirstElemnt,firstEquationSecondElemnt,firstEquationThirdElemnt],[secondEquationFirstElemnt,secondEquationSecondElemnt,secondEquationThirdElemnt],[thirdEquationFirstElemnt,thirdEquationSecondElemnt,thirdEquationthirdElemnt],[fourthEquationFirstElemnt,fourthEquationSecondElemnt,fourthEquationThirdElemnt], [fifthEquationFirstElemnt,fifthEquationSecondElemnt,fifthEquationThirdElemnt]]

let col:Int = Int(arc4random_uniform(UInt32(gameDifficulty.stages[gameLevel].umberOfVariables)))

let row:Int = Int(arc4random_uniform(UInt32(2))) * 2

let var_to_show = current_equations[col][row]
let image_name = "answer.num.\(var_to_show)"
for i in 0..<current_equations.count {
for j in 0..<current_equations[i].count {
if (current_equations[i][j] == var_to_show) {
var image_index = j
if (j > 0) {
image_index = Int(j/2) //Converting index
}
labelsArr[i][image_index]!.image = UIImage(named: image_name)! //Replacing the image
}
}
}
}

最后一件事,如果我想在动画中使用而不是让图像简单地淡出怎么办?我有哪些选择以及如何实现它们?

最佳答案

好的,我找到了答案。基本上,swift 允许您通过一个接一个地投影一组图像来创建动画。按着这些次序:1.将动画图片复制到assets文件夹中2. 创建 UIImage 数组3. 执行与 animate 函数中相同的操作

主要代码 -

var animationArray = createImageArray(total: 14, imagePrefix: "hint.animation")
animationArray.append(UIImage(named: imageHintAnswer)!)
animate(imageView: labelsArr[i][image_index]!, images: animationArray)

函数 -

func createImageArray(total: Int, imagePrefix: String) -> [UIImage] {
var imageArray:[UIImage] = []
for imageCount in 1..<total {
let imageName = "\(imagePrefix).\(imageCount)"
let image = UIImage(named: imageName)!

imageArray.append(image)
}

return imageArray
}

func animate(imageView: UIImageView, images: [UIImage]) {
imageView.animationImages = images
imageView.animationDuration = 0.7
imageView.animationRepeatCount = 1
imageView.startAnimating()
}

关于ios - 动画图标变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48508663/

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