How to add your own view from the Cordova plugin

I am developing a plugin with the latest version of Cordoba (3.3). I need to add a native UIImageView to the Cordoba view.

If I have access to the project, for example, in the platform folder, I can add my view to the view instance owned by CDVViewController . However, I am not sure how to access this link from the plugin.

Inside my plugin, I have:

 @interface CDVCool : CDVPlugin @property (weak, nonatomic) UIImageView *nativeImageView; ... @end 

How can I initialize and visualize this view by changing only the plugin files?

+1
source share
1 answer

The credit for this answer goes to devgeeks , who pointed out to me a couple of his plugins, MapKit and VolumeSlider , which mix in the native elements with the cordova web view.

The key is to overwrite the initWithWebView :

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

Now, inside the plugin, you can get a link to the view controller located behind the cordless web view and add to it whatever your heart desires.

 [self.webView.superview addSubview:mpCustomView]; 

This is cool because you can control zPosition of any views you add in relation to webView. This way you can place the views above or below the web view.

+2
source

Source: https://habr.com/ru/post/1480309/


All Articles