是否可以使用标准的 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].
除了推送到 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.
我希望这对某人有帮助!
I hope this helps someone!
这篇关于iPhone 应用中的全局 ADBannerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!