我希望在单击按钮时运行简单的图像数组动画。下面的代码运行良好,但我希望将数组中的最后一个图像设置为之后的imageview图像。如何在完成时更改图像而不是返回到原始图像?
let imageArray = [UIImage(named: "Frog-1.gif")!, UIImage(named: "Frog-2.gif")!, UIImage(named: "Frog-3.gif")!, UIImage(named: "Frog-4.gif")!]
@IBOutlet var imageView1: UIImageView!
@IBAction func button1(sender: UIButton) {
imageView1.animationImages = imageArray
imageView1.animationDuration = 1.0
imageView1.animationRepeatCount = 1
imageView1.startAnimating()
}
答案 0 :(得分:5)
在最后的解决方案中添加#selector()和@objc并尝试:
按下按钮时,您可以调用延迟功能
self.performSelector(#selector(afterAnimation), withObject: nil, afterDelay: imageView1.animationDuration)
然后停止动画并将imageArray
的最后一张图像添加到imageView
函数中的afterAnimation
@objc func afterAnimation() {
imageView1.stopAnimating()
imageView1.image = imageArray.last
}