我目前正在开发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库。
答案 0 :(得分:0)
您可以使用在该错误之前定义的rootController.Thanks