[英]How to vertically align iAd view in Admob for iOS?
我甚至试过设置contentMode
,Admob的视图没有垂直对齐广告。
例如,我将广告视图添加到视图层次结构中,并将其赋予90px高度,这与Admob的大小常量相同。 因此,当Admob自己的广告加载时,它会完美填补空间。
另一方面,由于文档的iAd高度为66px。 它显示在Admob视图的顶部..不垂直居中。 因此iAd横幅下方有24px空白区域。
我无法找到一种安全的方法来垂直对齐给定高度的所有东西。(90px)
我怎样才能做到这一点?
您可以通过检查的大小找出中介广告的大小mediatedAdView
AdMob广告横幅广告视图中。 要将广告垂直居中,只需计算出mediatedAdView
与横幅视图之间的高度差异,将其减半,然后按该数量调整横幅视图的位置。 并且不要忘记在没有调解内容时重新调整位置,否则广告将再次不对齐。
下面的代码示例演示了一个名为adMobBannerView
的横幅视图 -
此代码可以进入每次加载新广告时调用的委托处理程序。
// What is the normal vertical position of the ad? For this example, the vertical position is sitting at the bottom of the screen.
int adViewNormalY = self.view.bounds.size.height - adMobBannerView.frame.size.height;
// By default, assume there is no empty space in the ad
int emptySpaceAtBottomOfAd = 0;
// Check that this is a mediated ad, not a normal AdMob ad
if (adMobBannerView.mediatedAdView)
{
// Subtract the height of the mediated ad from the ad view
emptySpaceAtBottomOfAd = adMobBannerView.frame.size.height - adMobBannerView.mediatedAdView.frame.size.height;
}
// Move the ad view down so that the mediated ad appears centered
CGRect newFrame = adMobBannerView.frame
newFrame.origin.y = adViewNormalY + (emptySpaceAtBottomOfAd / 2);
adMobBannerView.frame = newFrame;
祝好运!
不幸的是, 似乎没有标准的API来告诉您给定提供商的实际广告高度 。 在我的例子中,我使用了kGADAdSizeSmartBannerPortrait
,无论你是在iPad
还是iPhone
上,都应该正确调整GADBannerView
大小。 但是,由于iAd仅在iPad上以纵向模式使用66px ,但Google Mobile Ads智能横幅在iPad上以纵向模式保留90px ,因此我的广告底部有空白空间。
为了解决这个问题,我使用了-[GADBannerView adNetworkClassName]
并查找了GADMAdapterIad
的值来确定我是否正在显示iAd。 如果是这样,我手动调整GADBannerView
大小为66px高。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.