Same WebView on every view

2019-06-24 03:50发布

Basically i have a WebView on SecondViewController and I wish for the WebView to be visible on every view like a tab bar and fully controllable on each view.

Please note the WebView will be on a webpage with a online slideshow so I cannot simply reload on each view

Also in the SecondViewController I have

- (void)webViewDidFinishLoad:(UIWebView *)YouTubePlayer {

8条回答
等我变得足够好
2楼-- · 2019-06-24 04:30

You can have all your views take up a portion of the screen and have your UIWebView take up the rest. The logic for switching between the other views should remain the same.

For example, in your viewDidLoad method for your UIViewControllers, you could have something like:

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

And in your (say) AppDelegate, you would have your normal call to show the main UIViewController (in your case, it sounds like a UITabBarController?) and also have a call to add the UIWebView. Say, something like:

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

The view controllers and UIWebView would be independent of each other.

You see this pattern, I believe, with apps that have iAds. I've done something just like this with one of my free apps.

Hope this helps!

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-06-24 04:36

Could you not use two webviews on your application and simply change the uppermost webview with your more dynamic content?

查看更多
别忘想泡老子
4楼-- · 2019-06-24 04:40

I would suggest adding the webView on you window after the you add the tabbarcontroller.view just like:

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

and initially make don't make it visible. You should handle all the webview related methods in the app delegate. Now whenever you don't need it you can hide it by calling the methods your wrote in app delegate from your view controllers.

Hope this helps.

查看更多
smile是对你的礼貌
5楼-- · 2019-06-24 04:46

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

查看更多
姐就是有狂的资本
6楼-- · 2019-06-24 04:52

Sounds like you try to put views on top of this view but not modal. There was this blog entry I once saw that described how you would do something like this. I think it should apply also for your case: semi-modal-transparent-dialogs-on-the-iphone

查看更多
beautiful°
7楼-- · 2019-06-24 04:53

The simplest approach is to just make all of your view controllers aware of this extra view (make the view available through a singleton PinnedViewController or whatever). During each view controller's -viewWillAppear, just do this:

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

This will move the view to whoever is currently active (making a view your subview automatically removes you from your old hierarchy).

If that is cumbersome or otherwise unworkable, there are two other options. First, you can subclass UITabViewController (I assume that's what you're using here from your question), and inject your extra view (resizing the content view to make room). This is undocumented and unsupported, so take heed. But it's not incredibly difficult if you don't do too many other fancy tricks.

The other tricky solution is to create a second UIWindow that you float over the main UIWindow (or resize the main UIWindow to make room for it). This is only semi-documented and is also not really supported. But this approach can work if you're trying to put the extra view below the tabbar for instance.

But if your system is simple enough, I recommend just letting your view controllers all manage the pinned view manually. You'll save a lot of code spelunking that way, and you won't have to rely on any undocumented internal view hierarchies.

查看更多
登录 后发表回答