将 ADBannerView 放在 UINavigationController 之上

发布于 2024-10-31 19:21:33 字数 686 浏览 0 评论 0原文

我正在尝试将 iAd 横幅放入基于 UINavigationController 的应用程序中(它不是 xcode 提出的标准导航基础应用程序,因为我不需要表视图)。 我想在其底部放置一个 ADBanner,无论用户如何弹出和推送视图,它始终可见。

我研究了苹果示例代码中的 iAdSuite 示例,但是,尽管它被报告为“最佳实践”,但我不认为它是满足我需要的最佳实践。它基本上在应用程序委托类中声明一个 ADBannerView,然后为应用程序需要的每个视图实现 ADBannerViewDelegate 方法。这意味着在您需要的每个视图控制器类上一遍又一遍地实现 ADBannerViewDelegate 方法!它看起来不太聪明... :(

我宁愿采用一种更类似于苹果本身在基于选项卡栏的应用程序中所做的方法,其中窗口的一部分始终被选项卡控制器占据,并且上面的所有视图切换都不影响下面的选项卡栏视图。 您不能直接将 ADBannerView 与导航控制器一起放入应用程序委托中,因为 ADBanner 需要放置在视图控制器中(否则会出现运行时错误)。

我尝试从 UIViewController 进行子类化,在此类中实现 ADBannerViewDelegate,并将其与 UINavigationController 一起放置在 rootViewController 中,但我在这种方法上运气不佳...

有人找到了一种好的、简单的方法吗?有什么提示吗?

谢谢您的帮助...

I'm trying to put an iAd banner in an app that is based on a UINavigationController (it's not the standard nav-base app proposed by xcode, cause I don't need the table view).
I'd like to place an ADBanner on its bottom, to be always visible, no matter how the user pops and pushes views.

I studied the iAdSuite example in the apple sample code, but, though it's reported among the "best practices", I don't think it's the best practice for what I need. It basically declares an ADBannerView in the app delegate class and then implements the ADBannerViewDelegate methods for every single view the app needs. That means implementing the ADBannerViewDelegate methods over and over again on every view controller class you need! It doesn't seem too smart... :(

I'd rather prefer to have an approach more similar to what Apple itself does in the tab bar based app, where you have a part of the window always occupied by the tab controller and all the views switching above without affecting the tab bar view below.
You can't directly put an ADBannerView along with the nav controller in the app delegate, because ADBanner needs to be placed in a view controller (you get a runtime error otherwise).

I tried to subclass from UIViewController, implementing the ADBannerViewDelegate in this class, and place it in the rootViewController along with a UINavigationController but I'm not having good luck with this approach...

Has anybody found a good, simple way to to this? Any hint?

Thank you for any help...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼性发作 2024-11-07 19:21:33

您可以只有一个 ADBannerViewDelegate 类,以及 ADBanner 本身的一个实例。当当前活动视图发生更改时,从旧视图中删除 ADBanner,将其作为子视图添加到新视图中。

编辑:

澄清一下,您不需要每个视图都实现 ADBannerViewDelegate。您应该只让一个类实现它(该类不必是视图控制器)。

您还需要在某处维护一个指向当前活动视图的属性(例如,您可以在导航控制器的 navigationController:didShowViewController:animated: 中更新该属性,或者提出您自己的协议如果你的观点以更复杂的方式出现的话)。

然后在您的 ADBannerViewDelegate 中,您只需调整当前视图属性当前指向的视图的大小。实际视图甚至不必知道其中有广告;)

You can have just one class for ADBannerViewDelegate, and just one instance of ADBanner itself. When the currently active view changes, remove ADBanner from the old view, add it as a subview to the new view.

EDIT:

to clarify, you don't need each view implement the ADBannerViewDelegate. You only should have one class implement it (that class doesn't have to be a view controller for that matter).

You would also need to maintain a somewhere a property that would point to the currently active view (e.g. you can update that property in your Navigation Controller's navigationController:didShowViewController:animated:, or come up with your own protocol for that if your views appear in a more complex way).

Then in your ADBannerViewDelegate you'd just resize the view currently pointed to by that current view property. The actual view doesn't even have to know it has an ad in it ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文