使用来自SKScene的xib呈现视图控制器

时间:2014-02-26 20:00:37

标签: ios objective-c sprite-kit skscene

我尝试过很多东西,但都没有。我有一个 SKScene ,当游戏结束时,我希望它回到原始视图控制器。先感谢您。

我在SKScene中试过这个

homeScreenViewController *viewCont = [[homeScreenViewController alloc] init];
            [viewCont viewDidLoad];

这在我的其他视图控制器中

constructinoViewController *view = [[constructinoViewController alloc ] init];
        [self presentViewController:view animated:YES completion:nil];

主要是说视图不在视图层次结构中

2 个答案:

答案 0 :(得分:0)

您需要一种向父viewController发送消息的方法。

在展示SKScene的viewController中,在viewDidLoad中添加以下行:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeScene) name:@"closeScene" object:Nil];

另外,添加此方法

-(void)closeScene
{
    //Remove the SKView, or present another viewController here.

    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"closeScene" object:nil];
}

然后在你的SKScene中,在你的游戏结束时,

[[NSNotificationCenter defaultCenter] postNotificationName:@"closeScene" object:nil];

您也可以使用委托来完成此操作。

答案 1 :(得分:0)

如果您已经展示了ViewController,那么您需要将其关闭以返回到之前的ViewController。

你应该使用

[self dismissViewControllerAnimated:YES completion:NULL];
相关问题