如何以编程方式将iAd横幅添加到屏幕的顶部中心?

时间:2015-09-03 14:38:20

标签: ios swift iad

我一直想要将iAd正确地修复到我的屏幕顶部,我尝试了几种解决方案,但无济于事。我需要解决这个问题,当你断开连接时,你会得到一个白色矩形代替iAd横幅,有时候它会出现在顶部,有时会出现在底部。如何让它始终显示在顶部中心,而不是随机地从上到下,从下到上?

我的代码:

class ViewController: UIViewController, ADBannerViewDelegate, UITextFieldDelegate  {
    @IBOutlet var adBannerView: ADBannerView!
    var bannerIsVisible : Bool = false

    override func viewDidLoad() {
        super.viewDidLoad()

        self.canDisplayBannerAds = true
        self.adBannerView?.delegate = self
        self.adBannerView?.hidden = true
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
        self.adBannerView?.hidden = true
    }
    func bannerViewActionDidFinish(banner: ADBannerView!) {

    }
    func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
        return true
    }
    func bannerViewDidLoadAd(banner: ADBannerView!) {
        self.adBannerView?.hidden = false
    }
    func bannerViewWillLoadAd(banner: ADBannerView!) {
    }

1 个答案:

答案 0 :(得分:1)

设备屏幕底部显示的ADBannerViewself.canDisplayBannerAds = true创建。 self.canDisplayBannerAds = true可用于在应用程序中实现iAd横幅的无麻烦方式。这将为您创建ADBannerView,并根据其是否从iAd网络收到广告来显示或隐藏ADBannerView

您需要从self.canDisplayBannerAds = true中删除viewDidLoad