我正在尝试从Viewcontroller
内部恢复模式SceneDelegate
。
但是,此代码不允许模态视图控制器显示,并导致以下错误: "Unbalanced calls to begin/end appearance transitions for...".
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let userActivity = connectionOptions.userActivities.first ?? session.stateRestorationActivity {
// Restoring Data and Modal VC:
let storyboard = UIStoryboard(name: "Main", bundle: .main)
let splitController = storyboard.instantiateViewController(withIdentifier: "splitVC")
if let navigationController = window?.rootViewController as? UINavigationController {
splitController.modalPresentationStyle = .fullScreen
self.window?.makeKeyAndVisible()
navigationController.present(splitController, animated: false, completion: nil)
}
} else {
print("No User Activity")
// Loads Initial VC
}
}
有关如何解决此问题并从Viewcontroller
呈现模态SceneDelegate
的任何想法
答案 0 :(得分:0)
当您尝试在呈现一个新UIViewController的动画完成之前加载它时,就会发生这种情况。您应该只在主线程上异步调用演示文稿:
DispatchQueue.main.async { navigationController.present(splitController, animated: false, completion: nil) }