Решил воспользоваться вашим методом - не хватает опыта.
Можно образец как добавить и воспроизвести звук. Или укажите на ошибку
Благодарю
В 75 строке ошибка
import UIKit
import AVFoundation
class ViewController: UIViewController {
@IBOutlet weak var baskettop: UIImageView!
@IBOutlet weak var basketbottom: UIImageView!
@IBOutlet weak var fabrictop: UIImageView!
@IBOutlet weak var fabricbottom: UIImageView!
@IBOutlet weak var bug: UIImageView!
var isBugDead = false
let crash: AVAudioPlayer
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(_ animated: Bool) {
UIView.animate(withDuration: 0.7, delay: 1.0, options: .curveEaseOut, animations: {
var basketTopFrame = self.baskettop.frame
basketTopFrame.origin.y -= basketTopFrame.size.height
var basketBottomFrame = self.basketbottom.frame
basketBottomFrame.origin.y += basketBottomFrame.size.height
self.baskettop.frame = basketTopFrame
self.basketbottom.frame = basketBottomFrame
}, completion: { finished in
print("Basket doors opened!")
})
UIView.animate(withDuration: 1.0, delay: 1.2, options: .curveEaseOut, animations: {
var fabricTopFrame = self.fabrictop.frame
fabricTopFrame.origin.y -= fabricTopFrame.size.height
var fabricBottomFrame = self.fabricbottom.frame
fabricBottomFrame.origin.y += fabricBottomFrame.size.height
self.fabrictop.frame = fabricTopFrame
self.fabricbottom.frame = fabricBottomFrame
}, completion: { finished in
print("Napkins opened!")
})
}
required init(coder aDecoder: NSCoder) {
let crashSoundEffect = Bundle.main.path(forResource: "squish", ofType: "caf")
if let crashSoundEffect = crashSoundEffect
{
let crashSoundEffectURL = URL(fileURLWithPath: crashSoundEffect)
do {
try crash = AVAudioPlayer(contentsOf: crashSoundEffectURL)
crash.prepareToPlay()
}
catch {
}
}
super.init(coder: aDecoder)
}
}