override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var images = [UIImage]()//初始化一個數組,用來存放圖片素材
for i in 1 ... 19 {//創建一個循環,將導入的圖片依次存入數組中
images.append(UIImage(named: "animation\(i)")!)
}
let screenw = UIScreen.main.bounds.size.width
let imageView = UIImageView(frame: CGRect(x: 0, y: 60, width: screenw, height: 1050/700*screenw))
imageView.animationImages = images//設置圖像視圖的動畫圖片屬性
imageView.animationDuration = 38//設置幀動畫時長
imageView.animationRepeatCount = 0//設置無限次循環
imageView.startAnimating()//開始播放
self.view.addSubview(imageView)
let labelView = UILabel(frame: CGRect(x: 0, y: 70+1050/700*screenw, width: screenw, height: 30))
labelView.text = "Designed by Lisen"
labelView.textAlignment = NSTextAlignment.center
self.view.addSubview(labelView)
}
Xcode9學習筆記62 - 使用UIImageView製作幀動
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.