What does the iAd `UIViewController` category `canDisplayBannerAds` do?

十年热恋 提交于 2019-11-28 09:23:11

问题


In iOS7, the iAds framework includes the category -[UIViewController canDisplayBannerAds].

What does this category do and how should I use it?


回答1:


The headers for canDisplayBannerAds state:

Set this to enable automatic management of banner ad display with the view controller. It's important to note that this will modify the view hierarchy of the view controller by inserting a new container view above the view controller's view. The impact is that the view controller's view property will no longer return the originally provided view, it will return the new container. To access the original view, use the originalContentView property.

What is not clear is that automatic management also refers to instantiating and inserting an ADBannerView into your view hierarchy. You do not need to instantiate an ADBannerView, and you do not need an ADBannerView property or instance variable.

You will still want to adhere to the ADBannerViewDelegate protocol in your view controller so you can pause your application when the user taps the ad, and then resume when the fullscreen ad goes away.

Update: Unless you want to walk through the view hierarchy looking for the automatically inserted ADBannerView to set your view controller as a delegate, you can also cut the ADBannerViewDelegate protocol methods.




回答2:


You actually need to look at the docs for originalContentView to learn this:

When a view controller enables banner ads, the system puts the view controller’s content view inside of a new content view that the system manages. This allows the system to dynamically resize the original content view when a banner ad is displayed, as well as managing the display of the banner ad itself. This property provides access to the original content view, rather than the containing view that manages banner ad display.



来源:https://stackoverflow.com/questions/19521677/what-does-the-iad-uiviewcontroller-category-candisplaybannerads-do

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!