我有一個bar button item
繼續下一個視圖controller.I在欄按鈕項上執行show segue
,它有第一次延遲2秒然後它是正常的。延遲在執行Segue
我以前DispatchQueue
如下,但它仍然不相同
@IBAction func addPressed(_ sender: AnyObject) {
DispatchQueue.main.async(execute: {
self.performSegue(withIdentifier: "showDetail",sender: self)
})
}
這是我的第二個VC
override func viewDidLoad(){
super.viewDidLoad()
firstBtn.layer.borderWidth = 3
firstBtn.layer.borderColor = UIColor.white.cgColor
secondBtn.layer.borderWidth = 3
secondBtn.layer.borderColor = UIColor.white.cgColor
do{
let correctSoundUrl: URL = URL(fileURLWithPath: Bundle.main.path(forResource: "btnTap", ofType: "wav")!)
self.goalsTapPlayer = try AVAudioPlayer(contentsOf: correctSoundUrl)
self.goalsTapPlayer.prepareToPlay()
}
catch{}
}
嘗試與這一個DispatchQueue.main.async { self.performSegue(withIdentifier執行audioplayerloading: 「showDetail」,發件人:自己) } –
@ Anbu.Karthik,它仍然有這樣的延遲 – Coder221
是第二個VC加載的東西可能很重?也許嘗試加載'prepareForSegue'中的第二個VC? – Idan