我正在做一个小游戏与几个迷你游戏。在1.VC中,我有UIButtons在scrollView中选择迷你游戏。当加载miniGame ( UIVC)时,它会用所选的SKScene游戏加载SKView。
这是我的应用程序视图设置:
1.
UIViewController -> 1.1. ScrollView -> 1.1.1. UIButton -> 1.1.1.1. UIViewController -> 1.1.1.1.1. SKView -> 1.1.1.1.1.1. SKScene (the 1. mini game).
In the 1.1.1.1. VC I have a backButton (UIButton) which returns me back to the 1.VC.
Since I added the backButton in 1.1.1.1.VC I can always return at any moment in the first mini game to 1.VC.问题:从1.1.1.1返回的唯一方法。(或者更深一点)到1是通过单击UIButton来实现的。我想以编程的方式回去。当endGameVC (一个SKScene)出现时,我希望它自动地返回到1.VC (使用NSTimer)。
到目前为止,我已经尝试过:
1.
[self.view removeFromSuperview];结果:黑屏-不能在这里做任何事情。
2.
[self.view presentScene:nil];结果:灰色屏幕-我移除了skview,可以按一下按钮返回。
3.
[self.view removeFromSuperview];
[self.view addSubview:[[WBMGamesDataManager sharedInstance] tempy]];结果:
-[WBMMainVC superview]: unrecognized selector sent to instance 0x9ac4c30
2014-04-04 11:54:06.317 KinderApp[1940:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WBMMainVC superview]: unrecognized selector sent to instance 0x9ac4c30'..。我试过的其他东西没能让我得到任何东西。
欢迎任何想法或解决方案。如果你知道我做错了什么,或者整个方法是可疑的,我愿意接受评论/批评。谢谢:)。
发布于 2014-05-29 09:56:02
找到了解决办法:
在我的:
@implementation MiniGameConcept这是一个SKScene,我在我需要游戏结束的地方放置了以下代码:
[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];这将我引向1.VC,这是我的主屏幕,玩家可以选择迷你游戏集。
对我起作用了。我也找到了一个后退一步的方法,但这基本上让我进入了rootVC。带有NSLog的控制台输出显示VC名称。
发布于 2014-04-04 11:31:41
我假设您使用的方法是弹出当前的视图控制器。
[self.navigationController popViewControllerAnimated:YES];但是,要使其工作,您需要从承载UIViewController的SKView调用它,因此,取决于您需要以编程方式返回的位置,将UIViewController的引用传递给所需的视图,并创建一个只需调用上面一行的方法。
/////in UIViewController
-(void)popIt{
[self.navigationController popViewControllerAnimated:YES];
}
////in the view where you want to simulate the back method
[referenceToVC popIt];希望这有帮助,请随便问你是否有什么不清楚的地方。
https://stackoverflow.com/questions/22859720
复制相似问题