我开始学习反应原生组件创建。 我有一个SceneKit项目,在3d视图中显示单个计划(我从this tutorial开始)。
我的目标是桥接此视图以使用Javascript控制3D原生相机。
我不知道从哪里开始。网络上关于创建组件的所有资源都远远不是我的范围,使用外部库或者对于像我这样的新手来说还不够详细。
我的scenekit项目有树文件:
App代表:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
return true
}
}
查看控制器
import UIKit
import SceneKit
class ViewController: UIViewController {
// UI
@IBOutlet weak
var sceneView: SCNView!
// MARK: Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
sceneSetup()
}
func sceneSetup() {
let scene = SCNScene()
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeAmbient
lightNode.light!.color = UIColor(white: 0.5, alpha: 1)
scene.rootNode.addChildNode(lightNode)
let plan = SCNPlane(width: 20, height: 40)
plan.firstMaterial!.diffuse.contents = UIColor.whiteColor()
let planNode = SCNNode(geometry: plan)
planNode.transform = SCNMatrix4MakeRotation(-90, 1, 0, 0)
scene.rootNode.addChildNode(planNode)
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(0, 0, 50)
scene.rootNode.addChildNode(cameraNode)
sceneView.scene = scene
sceneView.allowsCameraControl = true
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
}
// MARK: IBActions
@IBAction func segmentValueChanged(sender: UISegmentedControl) {
}
// MARK: Style
override func preferredStatusBarStyle() - > UIStatusBarStyle {
return UIStatusBarStyle.LightContent
}
// MARK: Transition
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
sceneView.stop(nil)
sceneView.play(nil)
}
}
首先。这对于RN来说是不可思议的?
答案 0 :(得分:4)
这是一个非常古老的问题,但最近我自己这样做,并且能够让SceneKit作为UIView的子视图运行正常,利用React Native doc的iOS' Native UI Components&#39 ;教程作为这种方法的基础...希望它可以帮助某人。
经理文件
#import <React/RCTViewManager.h>
@interface RCTDeviceManager : RCTViewManager
@end
@implementation RCTDeviceManager
RCT_EXPORT_MODULE()
DeviceView *view;
- (UIView *)view
{
view = [[DeviceView alloc] init];
return view;
}
@end
UIView文件
import SceneKit
import UIKit
@objc(DeviceView)
class DeviceView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
// create a new scene
let scene = SCNScene(named: "art.scnassets/devices.scn")!
// add cameras, lighting etc
// SCNView & subview
let scnView = SCNView(frame: CGRect(x: 0, y: 0, width: 1024, height: 768))
self.addSubview(scnView)
scnView.scene = scene
}
}