gpt4 book ai didi

ios - presentScene 导致错误的 View 加载

转载 作者:行者123 更新时间:2023-11-28 16:11:31 25 4
gpt4 key购买 nike

我有一个名为 NeighborhoodViewController 的 viewController。它将场景加载到 viewController 中,称为 NeighborhoodScene.sks。这绝对没问题。我已经通过 NeighborhoodViewController 从场景中的特定节点设置了一个 segue。这两个函数控制这个:

func createSegue(title: String) {
performSegueWithIdentifier(title, sender: self)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let viewController: SearchViewController = segue.destinationViewController as? SearchViewController {
viewController.sceneName = "game_1_1"
}
}

一切正常。正在调用 segue。 segue 旨在调出另一个名为 SearchViewController 的 VC,它应该调出自己的场景 SearchScene1.sks。

这是它的代码:

import UIKit
import SpriteKit

class SearchViewController: UIViewController {
var sceneName: String?
var chosenScene: GameScene?

override func viewDidLoad() {
super.viewDidLoad()

if sceneName == "game_1_1" {
chosenScene = GameScene(fileNamed: "SearchScene1")
} // TODO: add the rest of the presented scenes here

if let scene = chosenScene {
// Configure the view.
let skView = self.view as! SKView
skView.showsPhysics = true
skView.showsFPS = true
skView.showsNodeCount = true

/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = false

/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
scene.viewController = self
skView.presentScene(chosenScene)
}
}
}

如果我打印出 skView 的 restorationidentifier,它属于 SearchViewController 中的 View ,这是完美的。在 skView.presentScene(chosenScene) 之前一切似乎都工作正常,此时它似乎随机设置了 NeighborhoodViewController?我如何让它调用 SearchViewController 和关联的 sks 场景 -- SearchScene1?

最佳答案

segue 用于首先引入 nextviewcontroller。

关于ios - presentScene 导致错误的 View 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39491496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com