在SpriteKit Game的主ViewController中调用presentViewController [英] Calling presentViewController in main ViewController of SpriteKit Game
问题描述
我正在构建"spritekit"游戏,我需要展示除主游戏viewcontroller
之外的另一个viewController
.
我试图与代表和通知中心一起执行此操作,以发送请求以呈现新的视图控制器.两种方法都可以从"SkScene"(tuGameOver)在主viewController
(tuViewController)内部正确调用此函数.关键是要正确显示FacebookLikeViewDemoViewController
I'm building "spritekit" game, i need to present another viewController
than main viewcontroller
.
I tried to perform this with delegates and with notification center to send ask to present new view controller. Both ways correctly called this function inside main viewController
(tuViewController) from "SkScene" (tuGameOver). The point is to correctly present 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错误.
When this function is executed i got NSlog
and after that terminating with uncaught exception of type NSException
SIGABRT Error.
我还尝试将此功能修改为:
I also tried to modify this function to :
-(void)showShareScreen{
NSLog(@"VIEWCONTROLER RECEIVED");
UIViewController *vc = [[UIApplication sharedApplication] keyWindow].rootViewController;
FacebookLikeViewDemoViewController *helpVC = [[FacebookLikeViewDemoViewController alloc]init];
[vc presentViewController: helpVC animated: YES completion:nil];
}
有了这个,我没有崩溃,并出现了一些东西,但这是黑屏.
And with this, i didn't get crash, and something appears but this is blank black screen.
FacebookLikeViewDemoViewController
是典型的viewController
类,固定在情节提要中查看Controller.
有什么想法吗?
FacebookLikeViewDemoViewController
is typical viewController
Class, pinned up to view Controller in storyboard.
Any ideas?
推荐答案
Mc.Lover (笑声)来了提出了在SKScene中展示VC的解决方案.以下是他的解决方案的要点.我已将其添加到touchesBegan:方法中,因此您可以轻松对其进行测试.
Mc.Lover (chuckle) came up with a solution for presenting a VC in SKScene. Below is the gist of his solution. I have added it to the touchesBegan: method so you can easily test it.
-(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];
}
他的原始问答在此处.
这篇关于在SpriteKit Game的主ViewController中调用presentViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!