有人可以向我解释一下Cordova iOS插件的生命周期吗?
特别是,我有一个我正在尝试开发的插件,其中包含UIView
(和关联的UIViewController
)。
如何从我的扩展UIView
类中获取Cordova CDVPlugin
,这样我就可以将我的插件添加为子视图(这是它的工作原理吗?)。
我想暂时在我的Cordova应用程序上显示我的UIView
,然后将其关闭,返回我的JS / HTML应用程序。
答案 0 :(得分:17)
如果你想在cordova webview上展示整个UIViewController(全屏),你可以做到
[self.viewController presentViewController:yourViewController animated:YES completion:nil];
示例:
如果您只想在cordova webview上添加一个视图,可以
[self.viewController.view addSubview:yourView];
示例:
不同之处在于,第一种方法呈现整个视图控制器,全屏,第二种方法显示的视图可以具有您想要的大小和位置,如果您没有使它具有相同的设备大小屏幕用户将在其下方看到您的cordova webview
答案 1 :(得分:1)
请参阅@jcesarmobile上面给出的答案
对于像我这样无法识别如何定义yourViewController的未成熟iOS开发者,请按照下面的代码
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * yourViewController = [storyboard instantiateViewControllerWithIdentifier:@"iController"] ;
[self.viewController presentViewController: yourViewController animated:YES completion:nil];
其中Main是storyboard文件名,iController是view.Stroller在Main.Storyboard文件中定义的storyboardIdentifier
请投票给@jcesarmobile提供的上述答案