【问题标题】:Adding Google Cardboard SDK to a React Native project将 Google Cardboard SDK 添加到 React Native 项目
【发布时间】:2016-12-29 21:45:59
【问题描述】:

我目前正在开发一个 React Native 应用程序,除其他外,它需要使用 Google Cardboard SDK 显示全景图。我似乎已经设置了大部分东西,但鉴于我对 Objective-C 的了解非常有限,我无法连接拼图的所有端口。

目前,我的 javascript 与 Objective-c 连接,所以一切都很好,但是,查看 Cardboard SDK 中的示例代码,定义了 UIViewController 类型的 PanoramaViewController 和页面的必要元素(文本,实际全景查看器, 等) 使用类似的方式添加到视图中:

[_scrollView addSubview:_panoView];

在我的情况下,鉴于我正在使用 NSObject RCTBridgeModule 类型定义我的 ViewController,如果我理解正确,我无法做到这一点,除非我没有遗漏其他东西。

我一直在四处寻找解决此问题的最佳方法,而我发现的内容大致如下:

UIViewController *rootController = UIApplication.sharedApplication.delegate.window.rootViewController;
[rootController presentViewController:MyViewController animated:YES completion:nil];

在上面,我不知道我必须传递什么而不是 MyViewController,因为据我了解,Cardboard SDK 只创建视图,而我负责创建实际的 ViewController。

目前,我的 ViewController.h 是这样的:

#import <Foundation/Foundation.h>
#import "RCTBridge.h"

@interface GCViewController : NSObject <RCTBridgeModule>

@end

这就是我的 ViewController.m 的样子:

#import "GCViewController.h"
#import "AppDelegate.h"
#import "RCTLog.h"
#import "GCSPanoramaView.h"

@interface GCViewController ()<GCSWidgetViewDelegate>
@end

@implementation GCViewController {
    GCSPanoramaView *_panoView;
}

RCT_EXPORT_MODULE();

-(void)show360Video {

    _panoView = [[GCSPanoramaView alloc] init];
    _panoView.delegate = self;
    _panoView.enableFullscreenButton = YES;
    _panoView.enableCardboardButton = YES;
    [_panoView loadImage:[UIImage imageNamed:@"test.jpg"]
            ofType:kGCSPanoramaImageTypeMono];

    UIViewController *rootController = UIApplication.sharedApplication.delegate.window.rootViewController;
    [rootController presentViewController:XXXXXX animated:YES completion:nil];

}

RCT_EXPORT_METHOD(showVideo) {
    [self show360Video];
}

@end

如果有人可以帮助我,我将不胜感激。谢谢!

PS:在这个项目中,我使用的是 Google Cardboard v0.7.2,而不是新的 Google VR 库。

【问题讨论】:

  • 嗨@pol6880,你解决了这个问题吗?

标签: objective-c react-native google-cardboard


【解决方案1】:

您可以使用在该错误之前定义的 rootController。谢谢

【讨论】:

  • 是的,但是怎么做?请给我们举个例子
猜你喜欢
  • 2016-10-09
  • 1970-01-01
  • 2020-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多