在GameScene和ViewController Swift之间移动

问题描述 投票:1回答:1

当我触摸图像并在触摸UIButton时返回到GameScene时,我想从我的GameScene移动到ViewController。它从ViewController到GameScene,因为它是UIButton。

我这样做了:

@IBAction func playbut(sender: UIButton) {
    var scene = GameScene(size: CGSize())
    let skView = self.view as! SKView!
    skView.ignoresSiblingOrder = true
    scene.scaleMode = .ResizeFill
    scene.size = skView.bounds.size
    skView.presentScene(scene)
}

但是当我触摸GameScene上的那个图像时,我不知道要写回哪些代码回到ViewController。

我该怎么写给GameScene?

谢谢

ios swift uibutton xcode6
1个回答
1
投票

我不认为这是你应该做的......你应该使用SKScene而不是UIViewController来导航/菜单。

但是,我发现的one post确实解释了这个(尽管它在Obj-C中):

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone"     bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"PurchasedVC"];
//Call on the RootViewController to present the New View Controller
[self.view.window.rootViewController presentViewController:vc animated:YES completion:nil];

Swift版应该看起来像这样(我不是专家,但语法也不错)...

var mainStoryboard = UIStoryboard(name: "Main_iPhone", bundle: nil)
var vc = mainStoryboard.instantiateViewControllerWithIdentifier("PurchasedVC") as! UIViewController
self.view.window?.rootViewController?.presentViewController(vc, animated: true, completion: nil)

就其他答案而言:

我希望有所帮助。我有同样的问题,说实话,看起来我一直都做错了!

© www.soinside.com 2019 - 2024. All rights reserved.