1
我是新來的Swift 3,目前做一個簡單的應用程序,以顯示隨機gif圖像,而用戶觸摸屏幕。我有2個gif圖像,當用戶觸摸屏幕時,它會顯示任一個。我如何讓它隨機顯示?如何使用Swift 3(Xcode 8.1)隨機顯示gif圖像?
我是新來的Swift 3,目前做一個簡單的應用程序,以顯示隨機gif圖像,而用戶觸摸屏幕。我有2個gif圖像,當用戶觸摸屏幕時,它會顯示任一個。我如何讓它隨機顯示?如何使用Swift 3(Xcode 8.1)隨機顯示gif圖像?
對於實施例中,我使用這個庫視圖GIF圖像:https://github.com/kirualex/SwiftyGif
var imagesName:[String] = ["image1.gif","image2.gif"]
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard touches.count == 1 else {
return
}
let index = Int(arc4random_uniform(1))
if let touch = touches.first {
self.gifImageView.image = UIImage(gifName: self.imagesName[index])
}
}