如何使用 ARKit / a swift ViewController 创建 React Native 组件?
How to create a React Native component using ARKit / a swift ViewController?
我们有一个基于 swift 的 ARKit
示例 Capturing Body Motion in 3D from the WWDC 2019. And we have a React Native app using native swift components, following the great instructions from Swift in React Native - The Ultimate Guide. Now we want to implement the view from the ARKit example 的项目作为 react-native 组件,但我只是不知道如何执行此操作。
ARKit example 使用 UIViewController
和 ARSessionDelegate
,这意味着我们必须在组件中包装不仅仅是一个简单的视图。
我找到了一些关于如何在 React Native 中呈现原生 UIViewController 的答案,但无法将此解决方案转换为 swift 代码并且无法使其工作与 ARKit example。你们有人知道如何连接吗?
好的,我现在明白了;-)
在 3D 示例 Capturing Body Motion 中,所有功能都在 UIViewController
中实现。对于本机反应中的每个组件,我们没有单独的 UIViewController
,而是 RCTViewManager
。
我们可以基于 ARView 创建自己的视图 class,并将 ARSessionDelegate
从 UIViewController
直接移动到这个新视图,包括 session
方法和所有对应的部分。
从 RCTViewManager
返回这个新 View van 的一个实例,瞧,它起作用了!
我们有一个基于 swift 的 ARKit
示例 Capturing Body Motion in 3D from the WWDC 2019. And we have a React Native app using native swift components, following the great instructions from Swift in React Native - The Ultimate Guide. Now we want to implement the view from the ARKit example 的项目作为 react-native 组件,但我只是不知道如何执行此操作。
ARKit example 使用 UIViewController
和 ARSessionDelegate
,这意味着我们必须在组件中包装不仅仅是一个简单的视图。
我找到了一些关于如何在 React Native 中呈现原生 UIViewController 的答案,但无法将此解决方案转换为 swift 代码并且无法使其工作与 ARKit example。你们有人知道如何连接吗?
好的,我现在明白了;-)
在 3D 示例 Capturing Body Motion 中,所有功能都在 UIViewController
中实现。对于本机反应中的每个组件,我们没有单独的 UIViewController
,而是 RCTViewManager
。
我们可以基于 ARView 创建自己的视图 class,并将 ARSessionDelegate
从 UIViewController
直接移动到这个新视图,包括 session
方法和所有对应的部分。
从 RCTViewManager
返回这个新 View van 的一个实例,瞧,它起作用了!