uiviewanimationoptions - uiview animation swift



如何在swift中完成imageView.startAnimating()? (1)

這個問題在這裡已經有了答案:

我想要一個簡單的圖像數組動畫單擊按鈕時運行。 下面的代碼工作正常,但我想數組中的最後一個圖像被設置為之後的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()

}

當按下按鈕時,可以延遲地調用一個功能

self.performSelector("afterAnimation", withObject: nil, afterDelay: imageView1.animationDuration)

然後停止動畫,並將imageArray的最後一個圖像添加到afterAnimation函數中的afterAnimation

func afterAnimation() {
    imageView1.stopAnimating()
    imageView1.image = imageArray.last
}




uiimageview