我有编程按钮从数组中获取图像,该按钮有两个元素,此按钮与计时器一起使用
func monsterButtons () {
movingBtn.isHidden = true
movingBtn = UIButton(frame: CGRect(x: randomValueBetween(min: 0, max: 250), y: randomValueBetween(min: 200, max: 500), width: 100, height: 100))
movingBtn.contentMode = .scaleAspectFit
movingBtn.imageView!.contentMode = .scaleAspectFit
movingBtn.setImage(array_monesterImage[randomValueBetween(min: 0, max: imageIndex-1)], for: .normal)
movingBtn.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
view.addSubview(movingBtn)
我正在尝试动画array_monesterImage中的每个元素,所以我添加了这段代码
UIView.animate(withDuration: 1, delay: 0, options: [.repeat], animations: {
let chknArray:[UIImage] = [UIImage (named: "chkn1.png")!,
UIImage (named: "chkn2.png")!,
UIImage (named: "chkn3.png")!,
UIImage (named: "chkn4.png")!]
self.movingBtn.imageView!.animationImages = chknArray
self.movingBtn.imageView!.animationDuration = 1.0
self.movingBtn.imageView!.startAnimating()
let crzyYelowArray:[UIImage] = [UIImage (named: "crzyYelow1.png")!,
UIImage (named: "crzyYelow1.png")!,
UIImage (named: "crzyYelow1.png")!,
UIImage (named: "crzyYelow1.png")!]
self.movingBtn.imageView!.animationImages = crzyYelowArray
self.movingBtn.imageView!.animationDuration = 1.0
self.movingBtn.imageView!.startAnimating()
但它不起作用..是否有另一种方法来动画array_monesterImage中的元素?