我是一个新手 Swift 程序员,正在开发他的第一个应用程序。作为简单游戏的一部分,我在中间的某个地方使用以下代码执行一个函数 (F(
if let vc = storyboard?.instantiateViewController(withIdentifier:
"P2CompetitionPopUpId") as? P2_Competition_Pop_Up {
vc.modalPresentationStyle = .overCurrentContext
present(vc, animated: true, completion: nil)
} else {
print("error creating P2_Competion_Pop_Up")
但是,当我运行它时,弹出窗口直到整个函数 (F( 执行后才会发生。这是为什么呢?如何让函数 (F( 在弹出窗口发生时暂停并在弹出窗口关闭后恢复?
将其包装成异步调用:
DispatchQueue.main.async {
if let vc = self.storyboard?.instantiateViewController(withIdentifier: "P2CompetitionPopUpId") as? P2_Competition_Pop_Up {
vc.modalPresentationStyle = .overCurrentContext
self.present(vc, animated: true, completion: nil)
} else {
print("error creating P2_Competion_Pop_Up")
}