【发布时间】:2021-06-26 14:12:10
【问题描述】:
我是第一次使用 SpriteKit,但在应用启动时遇到了问题:
无法将“UIView”(0x2038a8848)类型的值转换为“SKView”(0x2039f2658)。
This question 明确表示您必须将GameViewController 的view 自定义类设置为SKView,并解释如何使用情节提要。问题是我正在尝试以编程方式执行此操作,因为我删除了情节提要,但我不知道该怎么做。因为我习惯了 UIKit,所以这从来没有给我带来任何问题。
所以,在AppDelegate 我说:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = GameViewController()
window.makeKeyAndVisible()
self.window = window
return true
}
在GameViewController:
override func viewDidLoad() {
super.viewDidLoad()
let skView = view as! SKView
skView.ignoresSiblingOrder = true
gameScene = GameScene(size: view.frame.size)
gameScene!.scaleMode = .aspectFill
gameScene!.gameSceneDelegate = self
show(gameScene!, animated: true)
}
当我尝试将 VC view 向下转换为 SKView 时,我得到的只是上面的错误。
请问有人可以说明如何在这些条件下以编程方式启动应用程序吗?
【问题讨论】:
标签: ios swift sprite-kit skview