在SpriteKit Game的主ViewController中调用presentViewController

我正在构build“spritekit”游戏,我需要提出另一个viewController比主viewController 。 我试图与代表和与通知中心执行此发送请求呈现新的视图控制器。 这两种方法都正确地从“SkScene”(tuGameOver)主viewController (tuViewController)内调用此函数。 重点是要正确呈现FacebookLikeViewDemoViewController

 -(void)showShareScreen{ NSLog(@"VIEWCONTROLER RECEIVED"); FacebookLikeViewDemoViewController *helpVC = [[FacebookLikeViewDemoViewController alloc]initWithNibName:@"FacebookLikeViewDemoViewController" bundle:nil]; [self presentViewController: helpVC animated: YES completion:nil]; } 

当这个函数被执行时,我得到了NSlog ,之后terminating with uncaught exception of type NSException SIGABRT错误。

我也试着修改这个函数来:

 -(void)showShareScreen{ NSLog(@"VIEWCONTROLER RECEIVED"); UIViewController *vc = [[UIApplication sharedApplication] keyWindow].rootViewController; FacebookLikeViewDemoViewController *helpVC = [[FacebookLikeViewDemoViewController alloc]init]; [vc presentViewController: helpVC animated: YES completion:nil]; } 

与此同时,我没有得到崩溃,并出现一些东西,但这是空白的黑屏。

FacebookLikeViewDemoViewController是典型的viewController类,固定在故事板中查看Controller。 有任何想法吗?

Mc.Lover (笑)提出了一个在SKScene中呈现VC的解决scheme。 以下是他的解决scheme的要点。 我已经添加到touchesBegan:方法,所以你可以很容易地testing它。

 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UIView *Sview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 512, 512)]; UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"shareScoreImg.png"]]; image.frame = Sview.frame; [Sview addSubview:image]; UIGraphicsBeginImageContextWithOptions(Sview.bounds.size, Sview.opaque, 0.0); [Sview.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIActivityViewController* activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[screenshot] applicationActivities:nil]; UIViewController *vc = self.view.window.rootViewController; [vc presentViewController: activityViewController animated: YES completion:nil]; } 

他原来的问答就在这里 。

试试这个代码:

  FacebookLikeViewDemoViewController *helpVC = [[FacebookLikeViewDemoViewController alloc]initWithNibName:@"FacebookLikeViewDemoViewController" bundle:nil]; [self.navigationController pushViewController:helpVC animated:YES] ;