iOS:Admob智能横幅没有占据全宽

时间:2017-08-23 18:01:11

标签: ios uiviewcontroller admob uiwindow adbannerview

我创建了横幅:

    bannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)  
    bannerView.adUnitID = "ca-76543456707"
    bannerView.delegate = self

它应该是全宽,我将它添加到具有前导,下拉,上下限制的视图中。对于大多数广告,结果是全宽度。但有些人不是。为什么? 这是一个示例: enter image description here 这里的红色是视图的颜色。

如何制作全宽?

4 个答案:

答案 0 :(得分:1)

  

通常,手机上的智能横幅的纵向高度为50dp   和景观中的32dp。在平板电脑上,两者的高度通常为90dp   取向。

     

当图片广告不足以占用整个分配时   空间,图像将居中,任何一侧的空间都将   填写。

enter image description here

您还可以在AppStore上查看实时应用,您会注意到在更大宽度的设备上它们也会显示320宽度。

答案 1 :(得分:0)

广告图片的宽度不同,因为您使用DateTime取决于图片宽度,广告将会进行调整。它在Admob Documentation上正确解释。

智能横幅是一种广告单元,可以在任意方向上跨不同设备在任何屏幕尺寸上呈现屏幕宽度横幅广告。智能横幅通过“巧妙地”检测设备当前方向的宽度并使广告视图的大小来帮助处理不同设备中不断增加的屏幕碎片。

通常,手机上的智能横幅的纵向高度为50dp,横向高度为32dp。在平板电脑上,两个方向的高度通常为90dp。 当图片广告不足以占据整个分配的空间时,图片将居中,并且两边的空间都将被填充。

答案 2 :(得分:0)

您在哪个设备上看到此广告?
我的意思是谷歌对横幅尺寸有特定的指示here,标准横幅为320 * 50 所以,如果你在iPhone 4s,iPhone 5或iPhone SE上看到320宽度的广告。所以它会以全宽显示。但如果你看到像iPhone 6或iPhone 6+这样的大设备那么你会看到两边的边距 对于智能横幅, 他们还指定了here

  

通常,手机上的智能横幅的纵向高度为50dp   和景观中的32dp。在平板电脑上,两者的高度通常为90dp   取向。

     

当图片广告不足以占用整个分配时   空间,图像将居中,任何一侧的空间都将   填写。

答案 3 :(得分:0)

 func addBannerViewToView(_ bannerView: GADBannerView) {
   bannerView.translatesAutoresizingMaskIntoConstraints = false
   view.addSubview(bannerView)  

  if #available(iOS 11.0, *) {
      // In iOS 11, we need to constrain the view to the safe area.
      positionBannerViewFullWidthAtBottomOfSafeArea(bannerView)
    }
    else {
      // In lower iOS versions, safe area is not available so we use
      // bottom layout guide and view edges.
      positionBannerViewFullWidthAtBottomOfView(bannerView)
    }
}



    func positionBannerViewFullWidthAtBottomOfSafeArea(_ bannerView: UIView) {
      // Position the banner. Stick it to the bottom of the Safe Area.
      // Make it constrained to the edges of the safe area.
      let guide = view.safeAreaLayoutGuide
      NSLayoutConstraint.activate([
        guide.leftAnchor.constraint(equalTo: bannerView.leftAnchor),
        guide.rightAnchor.constraint(equalTo: bannerView.rightAnchor),
        guide.bottomAnchor.constraint(equalTo: bannerView.bottomAnchor)
      ])
    }

    func positionBannerViewFullWidthAtBottomOfView(_ bannerView: UIView) {
      view.addConstraint(NSLayoutConstraint(item: bannerView,
                                            attribute: .leading,
                                            relatedBy: .equal,
                                            toItem: view,
                                            attribute: .leading,
                                            multiplier: 1,
                                            constant: 0))
      view.addConstraint(NSLayoutConstraint(item: bannerView,
                                            attribute: .trailing,
                                            relatedBy: .equal,
                                            toItem: view,
                                            attribute: .trailing,
                                            multiplier: 1,
                                            constant: 0))
      view.addConstraint(NSLayoutConstraint(item: bannerView,
                                            attribute: .bottom,
                                            relatedBy: .equal,
                                            toItem: bottomLayoutGuide,
                                            attribute: .top,
                                            multiplier: 1,
                                            constant: 0))
    }