如何在精灵套件中呈现模态视图?
我如何使用Game Center或GameKit框架与Sprite Kit Xcode模板? 在Sprite套件中,它使用场景; 但通常查看排行榜,例如你需要“presentModalViewController”,但在SKView中是不可能的。
提前致谢!
Smick指出了我正确的方向,因为我遇到了类似的问题。 我需要从我的SKScene发送消息到主ViewController。 这对我来说是这样的:
在你的SKScene中,导入ViewController
#import "MyViewController.h"
然后发送一条消息:
[(MyViewController *)self.view.window.rootViewController myMethod];
您可以尝试在ViewController中创build一个方法,为您打开GameKit视图,这是从SKScene触发的。 感谢Smick!
presentModalViewController必须在您的SKView所在的视图控制器上调用。
您也可以在故事板中设置设置视图,即
然后,如果你添加一个精灵,并使用button,即_settingsBtn它将执行赛格
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* touch = [touches anyObject]; CGPoint location = [touch locationInNode:self]; if ([_settingsBtn containsPoint:location]) { UIViewController *vc = self.view.window.rootViewController; [vc performSegueWithIdentifier:@"settingsPushSegue" sender:self]; } }
然后,你可以使用unwind segue删除它,只是一个UIButton。
在你的视图控制器类中有这个
- (IBAction)unwindToHideSettingsModal:(UIStoryboardSegue *)unwindSegue { //NSLog(@"UNWILD"); }
所以,现在在故事板上,控制从你添加到绿色退出segue的button的拖动,并select上面的放松segue。
现在,您将按预期显示和隐藏。 您可以在故事板中devise您的设置UI等。
这应该让你开始。