我試圖爲一些孩子製作一個簡單的應用程序。我想顯示一張照片並將該照片鏈接到聲音。顯示圖像並將其鏈接到聲音
當孩子點擊「播放聲音」時,它應播放代表圖像的音頻。
到目前爲止我已經做了只顯示圖像,我已經把它放在Assets.xcassets,但我的問題是.. 如何將這些照片鏈接到一些音頻文件,並通過點擊「播放聲音」
這是我在ViewController.swift代碼:
@IBOutlet weak var viewImage: UIImageView!
var images: [UIImage] = [
UIImage(named: "photo1.png")!,
UIImage(named: "photo2.png")!,
UIImage(named: "photo3.png")!,
UIImage(named: "photo4.png")!,
UIImage(named: "photo5.png")!,
UIImage(named: "photo6.png")!,
UIImage(named: "photo7.png")!,
UIImage(named: "photo8.png")!
]
var currentImagesIndex = 0
@IBAction func nextImage(_ sender: Any) {
currentImagesIndex += 1
let numberOfImages = images.count
let nextImagesIndex = currentImagesIndex % numberOfImages
viewImage.image = images[nextImagesIndex]
}
到目前爲止,當我點擊下一張圖就說明了我一個新的照片,它的工作確定。現在我想要做的就是將「photo1-8」鏈接到音頻並播放它。
我會感謝任何形式的幫助, 拉杜
上的ImageView –