iPhone应用程序中的全局ADBannerView [英] global ADBannerView in iPhone app

查看:114
本文介绍了iPhone应用程序中的全局ADBannerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用标准的UINavigationController根应用程​​序是否可以在视图层次结构下方的屏幕底部显示单个ADBannerView?也就是说,如果不修改可以推送到根UINavigationController的每个视图控制器/视图,我可以看到全局ADBannerView吗?

Is it possible with a standard UINavigationController-rooted app, to have a single ADBannerView visible at the bottom of the screen, below the view hierarchy? That is, without modifying each view-controller/view that can be pushed to the root UINavigationController, can I have a global ADBannerView be visible?

我不知道如何在IB或代码中进行设置。帮助?

I'm not sure how to set this up, either in IB or in code. Help?

我看到类似的问题和模糊的答案。我正在寻找一个具体的例子。

I see similar questions with vague answers. I'm looking for a concrete example.

推荐答案

编辑:在iOS5 +中执行此操作的更好方法可能是使用视图控制器包含。也就是说,制作一个包含广告和应用程序控制器的根控制器(导航,标签等)。

我找到了一种方法来做到这一点。这是我做的:

I figured out a way to do this. Here is what I did:

在我的第一次尝试中,我创建了一个名为AdBannerController的新视图控制器。为了它的视图,我创建了一个全屏视图和两个子视图。第一个子视图(contentView)用于常规内容,第二个是AdBannerView。我使用此视图控制器的实例作为与应用程序窗口关联的视图控制器([window addSubview:adBannerController.view])。然后我添加了我的UINavigationController.view作为adBannerController.view的子视图:[adBannerController.contentView addSubview:navigationController.view]。

For my first attempt I created a new view controller called AdBannerController. For its view I created a full-screen view and two subviews. The first subview (contentView) is for regular content, the second is the AdBannerView. I used an instance of this view controller as the view controller associated with the app window ( [window addSubview: adBannerController.view] ). Then I added my UINavigationController.view as a subview of adBannerController.view: [adBannerController.contentView addSubview: navigationController.view].

除了v​​iewcontrollers推送到UINavigationController永远不会调用它们的will / did-load / unload方法。哪里哪里。我在一些地方读到,这是UINavigationController视图不是应用程序窗口的直接后代的症状。

This mostly worked except that viewcontrollers pushed to the UINavigationController never got their will/did-load/unload methods called. Shucks. I read in a few places that this is a symptom of the UINavigationController view not being a direct descendant of the app window.

对于我的第二次尝试,我采用了相同的AdBannerController,从UINavigationController派生出来。这次,我在loadView中执行了以下操作:

For my second attempt I took the same AdBannerController and derived it from UINavigationController. This time, I did the following in loadView:

- (void)loadView
{
    [super loadView];

    _contentView = [self.view retain];

    self.view = [[[UIView alloc] initWithFrame: _contentView.frame] autorelease];

    [self.view addSubview: _contentView];

    _adView = [[ADBannerView alloc] initWithFrame: CGRectMake(0, _contentView.bounds.size.height, 320, 50)];
    _adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
    _adView.delegate = self;

    [self.view addSubview: _adView]; 

    /* for visual debugging of view layout
    [[_mainView layer] setCornerRadius: 6.0];
    [[_mainView layer] setMasksToBounds: YES];
    [[_mainView layer] setBorderWidth: 1.5];
    [[_mainView layer] setBorderColor: [[UIColor grayColor] CGColor]];  
     */
}

注意发生了什么 - 我让超类UINavigationController构造它的常规内容视图,但我将其换出并用我自己的视图替换它,这是内容和广告视图的容器。

Notice what happens - I let the superclass UINavigationController construct its regular "content" view, but I swap it out and replace it with my own view which is a container for both the content and ad views.

这很好用。我也使用了three20,并且需要一些东西才能使这个设置工作,但也不是太糟糕。

This works pretty well. I'm also using three20 and there were a few things required to make this work with that setup, but not too bad.

我希望这有助于某人!

这篇关于iPhone应用程序中的全局ADBannerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆