いつもお世話になります。
UIAlertController
/alert
/actionSheet
のボタンタップ時に遅延なくタップ音を鳴らす方法はありますか?
ご存知でしたら教えてください。
下記の方法では、アラート上のok
/cancel
をタップ後、アラートが非表示になってからワンテンポおいて音がなります。
swift
1import UIKit 2import AudioToolbox 3 4class ViewController: UIViewController { 5 6 override func viewDidLoad() { 7 super.viewDidLoad() 8 // Do any additional setup after loading the view, typically from a nib. 9 } 10 11 func playSound() { 12 AudioServicesPlaySystemSound(1104) 13 } 14 15 // これと同じタイミングで鳴らしたい storyboard/UIButtonのtouchUpInsideにつないであります。 16 @IBAction func soundBtnDidTap(_ sender: UIButton) { 17 playSound() 18 } 19 20 // アラートを表示してok/cancelタップ時に音を鳴らしたいがずれる 21 @IBAction func showAlertBtnDidTap(_ sender: UIButton) { 22 let alert 23 = UIAlertController(title: "alertTitle", 24 message: "alertMessage", 25 preferredStyle: .alert) 26 27 alert.addAction(UIAlertAction(title: "OK", style: .default, handler: {_ in 28 self.playSound()// <= だいぶずれる。})) 29 alert.addAction(UIAlertAction(title: "cancel", style: .cancel, handler: {_ in 30 self.playSound()// <= だいぶずれる。})) 31 self.present(alert, animated: true, completion: nil) 32 } 33 34}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/08 01:50 編集
退会済みユーザー
2019/03/08 01:49 編集
2019/03/08 04:06
退会済みユーザー
2019/03/09 04:30