更新时间:2023-11-17 13:36:04
最简单(尽管未记录)的方法是将视图控制器支持的 UIView
设置为 SCNPlane上材质的漫反射内容
(或任何其他几何体,但由于显而易见的原因,它最适合飞机)。
The simplest (although undocumented) way to achieve that is to set a UIView
backed by a view controller as diffuse contents of a material on a SCNPlane
(or any other geometry really, but it works best with planes for obvious reasons).
let plane = SCNPlane()
plane.firstMaterial?.diffuse.contents = someViewController.view
let planeNode = SCNNode(geometry: plane)
你必须将视图控制器保留在某处,否则它会继续被释放,飞机将不可见。只使用 UIView
而不使用任何 UIViewController
将引发错误。
You will have to persist the view controller somewhere otherwise it's going to be released and plane will not be visible. Using just a UIView
without any UIViewController
will throw an error.
关于它的***的事情是它保留了所有的手势,实际上只是作为一个简单的视图。例如,如果您使用 UITableViewController
的视图,您将能够在场景中向右滚动。
The best thing about it is that it keeps all of the gestures and practically works just as a simple view. For example, if you use UITableViewController
's view you will be able to scroll it right inside a scene.
我还没有在iOS 10及更低版本上测试它,但到目前为止它一直在iOS 11上运行。适用于普通的SceneKit场景和ARKit。
I haven't tested it on iOS 10 and lower, but it's been working on iOS 11 so far. Works both in plain SceneKit scenes and with ARKit.