有没有办法访问舞台正在运行的UIViewController?在RoboVM上有类似的东西,在安卓上我们有FXActivity来完成这样的任务……
谢谢和问候,丹尼尔
发布于 2017-02-08 13:23:08
如果你看一下plugins的魅力,它们中的一些需要在iOS上原生实现,在一些情况下,它们还需要访问UIViewController
。
例如,图片插件iOS implementation需要访问UIImagePickerController
,以创建添加到当前视图顶部的子视图。
为此,您需要声明一个接口:
@interface Pictures : UIViewController <...> {}
然后实现对该控制器的访问:
NSArray *views = [[[UIApplication sharedApplication] keyWindow] subviews];
UIView *_currentView = views[0];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[_currentView.window addSubview:picker.view];
请注意,iOS本机代码必须作为本机库进行编译和添加。
检查任务xcodebuild
here。您必须在build.gradle文件中使用它来构建本机库,然后将其复制到项目中的src/ios/jniLibs下。请参阅此question以获取其自定义用例。
https://stackoverflow.com/questions/42113178
复制