Ios 当我关闭模式显示的viewController时,我的游戏场景冻结
我正在制作SpriteKit游戏。在游戏场景中,我想表示另一个viewController。我做得很正确,但当我取消模式显示的viewController时,根viewController上的游戏场景冻结。这是我在游戏场景中的代码Ios 当我关闭模式显示的viewController时,我的游戏场景冻结,ios,swift,uiviewcontroller,sprite-kit,uimodalpresentationstyle,Ios,Swift,Uiviewcontroller,Sprite Kit,Uimodalpresentationstyle,我正在制作SpriteKit游戏。在游戏场景中,我想表示另一个viewController。我做得很正确,但当我取消模式显示的viewController时,根viewController上的游戏场景冻结。这是我在游戏场景中的代码 NotificationCenter.default.post(name: NSNotification.Name(rawValue:"present"), object:nil) 下面是我的根viewController(GameViewControll
NotificationCenter.default.post(name: NSNotification.Name(rawValue:"present"), object:nil)
下面是我的根viewController(GameViewController)代码
下面是另一个viewController的代码,它将在rootViewController上以模式表示:
override func viewDidLoad() {
super.viewDidLoad()
let imageView = UIImageView(image:UIImage(named:"Background1"))
imageView.frame = CGRect(x:0, y:0, width:1000, height:800)
let aButton = UIButton()
aButton.frame = CGRect(x:view.frame.width/2 - 50, y:view.frame.height/2 - 50, width:100, height:100)
aButton.setTitle("aButton", for: .normal)
aButton.backgroundColor = .green
aButton.addTarget(self, action: #selector(pressed), for: .touchUpInside)
aButton.isEnabled = true
view.addSubview(imageView)
view.addSubview(aButton)
}
func pressed(){
dismissVC()}
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if UIDevice.current.userInterfaceIdiom == .phone {
return .allButUpsideDown
} else {
return .all
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override var prefersStatusBarHidden: Bool {
return true
}
func dismissVC(){
self.dismiss(animated: true, completion: nil)
print("returning previous")
}
下面是答案和解释。首先,它不是处于冻结状态的游戏场景。但即使在modally presented viewController上的活动完成后,仍然存在另一个viewController的视图。另一个viewController的视图的存在是由于该viewController内未执行viewController解除代码。因此,另一个viewController视图不允许我与我的应用程序交互。现在的解决方案是,在上面的问题中,我在GameViewController代码中添加了presentVC()函数。在该行中,而不是在该行中:
self.present(toViewController, animated: true, completion: nil)
使用以下行:
self.show(toViewController, sender:nil)
我找到了这个问题的解决方案。如果你在发现问题后不想发布问题的答案,那么你应该删除这个问题。一个你知道答案但没有答案的开放式问题对任何人都没有好处亲爱的Ron Myschuk。。。我在前一天发布了这个问题,并在同一天找到了解决方案。。。。匆忙中,我忘了把全部答案贴在这里。我马上发布这个问题的答案。。。。。
self.show(toViewController, sender:nil)