iAd Reconfigures Screen: Need iAd to Appear in Front of Screen - Swift

426 views Asked by At

I have successfully implemented iAd in Swift, except when an ad appears, it reconfigures the dimensions of self. How do I make it such that the ad appears in front of the screen, and doesn't alter the size of the screen?

This is the code I used:

class GameViewController: UIViewController, ADBannerViewDelegate {

    var bannerView:ADBannerView?

    override func viewDidLoad() {
         super.viewDidLoad()

         super.viewDidLoad()
         self.canDisplayBannerAds = true
         self.bannerView?.delegate = self
         self.bannerView?.hidden = true
    }
    func bannerViewDidLoadAd(banner: ADBannerView!) {
         self.bannerView?.hidden = false
    }

    func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
         return willLeave
    }

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

How do I make it such that the ad appears in front of the screen, and doesn't alter the size of the screen?

1

There are 1 answers

0
Jason Bestor On

If you want to use self.candisplaybannerads = true without having the other items move on the screen make sure your items are not constrained to the bottom layout guide. When the ad loads using self.candisplaybannerads = true it moves up the location of the bottom layout guide so any items constrained to this will be moved. If your adding items programmatically you can setting the frame and they should not move when the ad loads. Or if you are using IB and constraints make sure your items are not constrained to the bottom layout guide.