The same webview on every view

Basically, I have a WebView on a SecondViewController , and I want the WebView appear in all views, such as the tab bar and fully controllable for each view.

Please note that the WebView will be on the web page with the online slide show, so I cannot just reload every view

Also in SecondViewController I have

 - (void)webViewDidFinishLoad:(UIWebView *)YouTubePlayer { 
+4
source share
8 answers

I just installed a singleton UIWebView and add it to each view-controller when that view controller becomes visible. Here is one way to do this:

 //.h @interface SharedWebView : UIWebView { } + (SharedWebView*) shared; @end //.m SharedWebView* g_sharedWebView; @implementation SharedWebView + (SharedWebView*) shared { if ( g_sharedWebView == nil ) { g_sharedWebView = [[SharedWebView alloc] init]; // ... any other intialization you want to do } return g_sharedWebView; } @end // in your view controller(s) @property (readonly) UIWebView* webView - (UIWebView*) webView { return [SharedWebView shared]; } - (void) viewWillAppear: (BOOL) animated { [super viewWillAppear: animated]; [self.view addSubview: self.webView ]; self.webView.frame = CGRectMake(10, 10, 300, 300); // want to re-set the delegate? // self.webView.delegate = self; } 
+1
source

I would suggest adding a webView to your window after adding tabbarcontroller.view in the same way:

 [window addSubview:tabbarController.view]; [window addSubview:webview]; [window makeKeyAndVisible]; 

and initially make it not visible. You must process all webview-related methods in the application delegate. Now that you don’t need it, you can hide it by calling the methods that you wrote in the application delegate from your view controllers.

Hope this helps.

+3
source

The easiest approach is to simply make all your view controllers of this optional view (make the view available through a singleton PinnedViewController or something else). During each -viewWillAppear view -viewWillAppear simply do the following:

 [self addSubview:[[PinnedViewController sharedController] view]]; 

This will move the view to the one who is currently active (viewing your preview automatically removes you from the old hierarchy).

If this is cumbersome or otherwise does not work, there are two more options. First, you can subclass the UITabViewController (I assume that you are using from your question here), and enter an additional view (resize the content to free up space). This is undocumented and not supported, so pay attention. But it is not incredibly difficult if you do not do too many other fancy tricks.

Another tricky solution is to create a second UIWindow that you float on the main UIWindow (or resize the main UIWindow to make room for it). This is only semi-documented and also not supported. But this approach may work if you want, for example, to add an additional view under the panel.

But if your system is simple enough, I recommend simply letting your view controllers manually control the manual view. You save a lot of code markup this way, and you don't have to rely on any undocumented internal view hierarchies.

+1
source

It sounds like you're trying to put views on top of that view, but not modally. There was a blog post that I once saw that described how you would do something like that. I think it should also apply for your case: semi-modal-transparent-dialogs-on-the-iphone

0
source

In iOS, UIViewControllers are expected to manage the whole "screen" of the cost of content, so you should not try to share the same view in many view controllers. Trying to have UIViewControllers whose views control only part of their window is problematic and will lead to unexpected behavior because UIKit will not send messages, such as -viewWillAppear, to all view controllers with visible views. Instead, you usually create a single UIViewController whose presentation includes this webview and any other views that make up your tab, such as an interface. In addition, you can have a hierarchy of many view controllers and add a single web view as a subview for all of them. You can then output the delegate behavior of your web view to some non-UIViewController controller class to control the behavior of the web view.

0
source

You can have all of your views occupying part of the screen, and your UIWebView will take care of the rest. The logic of switching between other views should remain unchanged.

For example, in your viewDidLoad method for your UIViewController s, you might have something like:

 self.view.frame = CGRectMake(0, 100, 320, 380); 

And in your (say) AppDelegate , you will have a regular call to show the main UIViewController (in your case, does it sound like a UITabBarController ?), And there is also a call to add a UIWebView . Say something like:

 myWebView.view.frame = CGRectMake(0, 0, 320, 100); 

View controllers and UIWebView will not be independent of each other.

You see this pattern, I suppose, with applications that have iAds. I did something similar using one of my free apps.

Hope this helps!

0
source

I got the same effect by simply adding it to the navigation controller itself (if you don’t have one, just add it). works great for me in one of my apps.

0
source

Could you use the two web views in your application and just change the topmost web view with your more dynamic content?

-1
source

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


All Articles