频繁点击按钮
Button Tapped Frequently
我试图让按钮播放大约 1 的声音 second.I 将事件更改为 "Touch Down" 因此当按钮被按下时,它开始播放声音。问题是,如果我在那 1 秒播放期间按下按钮,什么也不会发生,我必须等到声音结束。但我希望按钮忽略当前音频并重新开始播放。(有点像视频游戏,当用户按下拍摄按钮两次时会发出一声巨响)。我怎样才能在 swift 中做到这一点?
这是按钮的代码:
@IBAction func secondButton(sender: UIButton) {
brain.soundPlayer.play()
} // brain.soundplayer records anaudio and the button it as the sound.
你可以把你的AVAudioPlayer
的currentTime
设为0,然后用play
。
audioPlayer.currentTime = 0
audioPlayer.play()
您可以在按下按钮时停止和重新启动声音。
@IBAction func secondButton(sender: UIButton) {
brain.soundPlayer.stop()
brain.soundPlayer.play()
}
我试图让按钮播放大约 1 的声音 second.I 将事件更改为 "Touch Down" 因此当按钮被按下时,它开始播放声音。问题是,如果我在那 1 秒播放期间按下按钮,什么也不会发生,我必须等到声音结束。但我希望按钮忽略当前音频并重新开始播放。(有点像视频游戏,当用户按下拍摄按钮两次时会发出一声巨响)。我怎样才能在 swift 中做到这一点?
这是按钮的代码:
@IBAction func secondButton(sender: UIButton) {
brain.soundPlayer.play()
} // brain.soundplayer records anaudio and the button it as the sound.
你可以把你的AVAudioPlayer
的currentTime
设为0,然后用play
。
audioPlayer.currentTime = 0
audioPlayer.play()
您可以在按下按钮时停止和重新启动声音。
@IBAction func secondButton(sender: UIButton) {
brain.soundPlayer.stop()
brain.soundPlayer.play()
}