Merijn Den Houting
Merijn Den Houting

Reputation: 199

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

Upvotes: 1

Views: 345

Answers (2)

Daniel Storm
Daniel Storm

Reputation: 18878

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.

Upvotes: 2

0llie
0llie

Reputation: 8885

Only use the canDisplayBannerAds attribute. No need to do anything in storyboard or with callbacks. The ad moves in maintaining your autolayout constraints as defined. I went crazy with this, finding only complicated attempts. Watched this https://developer.apple.com/videos/play/wwdc2015-503/ and tried it. It's really that easy.

Upvotes: 1

Related Questions