Could not cast value of type 'UIView' to 'SCNView'

拟墨画扇 提交于 2019-12-05 20:31:20

Make sure to also import SceneKit at the top of the file.

import SceneKit

Open the “Main.storyboard” File. Select ViewController -> View go to “Identity Inspector” and change the Class field to SCNView. SceneKit Help

If you are setting all these stuff programmatically without storyboard, make sure to do these steps:

  1. General -> Deployment Info -> Clear the Main Interface section, leave empty.
  2. Go to AppDelegate.swift and assign rootViewController of window

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    window = UIWindow()
    let gameViewController = GameViewController()
    window?.rootViewController = gameViewController
    window?.makeKeyAndVisible()
    return true
}
  1. Go to GameViewController and here don't cast GameViewController's view to SCNView, instead create SCNView instance and add like subView:

let scnView = SCNView(frame: view.frame)
view.addSubview(scnView)

Same thing happened to me when I deleted a UIButton, which also deleted the UIView. So add a UIView and change class to SCNView

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!