【发布时间】:2015-08-25 21:49:14
【问题描述】:
我有一个用 animateWithDuration 和 setAnimationRepeatCount() 动画的脉动矩形。
我正在尝试在动画块中添加声音效果,女巫正在同步“点击”。但音效只播放一次。我在任何地方都找不到任何提示。
UIView.animateWithDuration(0.5,
delay: 0,
options: UIViewAnimationOptions.AllowUserInteraction | UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.Repeat,
animations: {
UIView.setAnimationRepeatCount(4)
self.audioPlayer.play()
self.img_MotronomLight.alpha = 0.1
}, completion: nil)
音效应该播放四次,但没有。
音频实现:
//global:
var metronomClickSample = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("metronomeClick", ofType: "mp3")!)
var audioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
audioPlayer = AVAudioPlayer(contentsOfURL: metronomClickSample, error: nil)
audioPlayer.prepareToPlay()
....
}
@IBAction func act_toggleStartTapped(sender: AnyObject) {
....
UIView.animateWithDuration(....
animations: {
UIView.setAnimationRepeatCount(4)
self.audioPlayer.play()
self.img_MotronomLight.alpha = 0.1
}, completion: nil)
}
【问题讨论】:
-
动画会重复吗?
-
有声音播放吗?音频剪辑有多长?
-
动画重复。声音只播放一次。音频剪辑只需点击一下:长度0.36 s,格式为mp3
标签: ios swift playback animatewithduration soundeffect