且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Cordova插件添加本机视图

更新时间:2023-11-17 18:49:04

这个答案的信用到 devgeeks ,他指出了我的几个插件, MapKit VolumeSlider ,它们以原生元素与cordova网络视图混合。

Credit for this answer goes to devgeeks who pointed me to a couple of his plugins, MapKit and VolumeSlider, that mix in native elements with cordova web view.

关键是覆盖 initWithWebView 方法:

-(CDVPlugin*) initWithWebView:(UIWebView*)theWebView
{
    self = (VolumeSlider*)[super initWithWebView:theWebView];
    return self;
}



现在在插件里面你可以获得一个对cordova web查看并添加到任何你的心愿望。

Now inside the plugin you can obtain a reference to the view controller behind cordova web view and add to it whatever your heart desire.

[self.webView.superview addSubview:mpCustomView];

这是很酷的,因为你可以控制您添加的任何视图的zPosition相对于webView。因此,您可以将视图置于Web视图的上方或下方。

This is cool becuase you can control the zPosition of any views you add with respect to the webView. So you can put views above or below the web view.