How can I add a native view from a Cordova plugin

大憨熊 提交于 2019-12-04 19:39:56

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.

The key is to overwrite the initWithWebView method:

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

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];

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!