use*_*000 1 animation uiimageview swift
我希望单击按钮时可以运行一个简单的图像数组动画。下面的代码运行良好,但我希望将数组中的最后一个图像设置为之后的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()
}
Run Code Online (Sandbox Code Playgroud)
在最后一个解决方案中添加#selector()和@objc并尝试:
按下按钮后,您可以延迟调用一个函数
self.performSelector(#selector(afterAnimation), withObject: nil, afterDelay: imageView1.animationDuration)
Run Code Online (Sandbox Code Playgroud)
然后停止动画的最后一个图像添加imageArray到imageView在afterAnimation功能
@objc func afterAnimation() {
imageView1.stopAnimating()
imageView1.image = imageArray.last
}
Run Code Online (Sandbox Code Playgroud)