Search code examples
iosswiftautolayoutiad

iAd ADBannerView using Auto Layout has multiple appearances


I am trying to add an ADBannerView to my application.

When there is no ad to show my label is visible because the ADBannerView is set to be hidden:

enter image description here

Then when the ADBannerView does load it SHOULD look like this:

enter image description here

Except sometimes the first time you load the app, and some other times in which I haven't found any regularity yet, the ADBannerView appears like this:

enter image description here

All the content above the ADBannerView is pushed upwards.

My question is, is there any way to control the way the ADBannerView behaves? Either way it does now is fine to me, as long as I know for sure that this is the way it is going to be viewed everytime.

The constraints are rather simple:

adBanner: - bottom 0 - left 0 - right 0 - height 50

label: - same as adBanner

start button: - bottom 60 - left, right 10 - height 30


Solution

  • Based on the information you've provided I'm assuming you've created an ADBannerView both with self.canDisplayBannerAds = true, and programmatically. self.canDisplayBannerAds = true can be used for a no hassle way of implementing iAds in your application. This will create an ADBannerView for you and show/hide the ADBannerView depending on whether it receives an ad or not from the iAd network.

    self.canDisplayBannerAds = true is also the reason for your UILabel being pushed upwards as you've described and shown in your third image. When your application first launches, whichever ADBannerView received an ad from the iAd network first is being favored. That is why sometimes your application looks like your second image, and sometimes your application looks like your third image.

    You have two options here, either remove self.canDisplayBannerAds = true from your application, which I would personally suggest, or, remove the ADBannerView you've created programmatically.