動畫 UIImageView
你可以使用 UIImageView 的動畫屬性通過在序列中快速顯示影象來為 UIImageView 設定動畫:
imageView.animationImages = [UIImage(named: "image1")!,
UIImage(named: "image2")!,
UIImage(named: "image3")!,
UIImage(named: "image4")!,
UIImage(named: "image5")!,
UIImage(named: "image6")!,
UIImage(named: "image7")!,
UIImage(named: "image8")!]
imageView.animationDuration = 0.3
imageView.animationRepeatCount = 1
animationImages 屬性是 UIImages 的 Array,在觸發動畫時從上到下貫穿。
animationDuration 屬性是一個 Double,表示動畫將執行多少秒。
animationRepeatCount 屬性是一個 Int,表示動畫將執行多少次。
要啟動和停止動畫,可以呼叫相應的方法來執行此操作:
imageView.startAnimating()
imageView.stopAnimating()
方法 isAnimating() 返回 Boolean 值,表示動畫是否正在執行。
請注意,這不是建立動畫的有效方式:它非常慢且耗費資源。考慮使用圖層或精靈來獲得更好的效果