Search code examples
swiftsprite-kitiad

ADBannerView in Spritekit (Swift). I cannot put it on the bottom of the view


In my GameViewControler.swift I have found the way to place the iad banner:

...
import SpriteKit
import iAd

var adBannerView: ADBannerView!

...

class GameViewController: UIViewController, ADBannerViewDelegate {    override func viewDidLoad() {

   ...

   loadAds() }

...
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
        println("Leaving app to the Ad")

        return true
    }

    func bannerViewDidLoadAd(banner: ADBannerView!) {

        //adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - view.bounds.size.height + adBannerView.frame.size.height / 2)
        adBannerView.frame = CGRectOffset(adBannerView.frame,0.0,0.0)
        adBannerView.hidden = false

        println("Displaying the Ad")
    }


    func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {

        adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height + view.bounds.size.height)
        println("Ad is not available")
    }


    func loadAds() {
        adBannerView = ADBannerView(frame: CGRect.zeroRect)   
        adBannerView.frame = CGRectOffset(adBannerView.frame,0,0.0)
        adBannerView.delegate = self
        adBannerView.hidden = true
        view.addSubview(adBannerView)
}

But, the problem is that the banner appears in the top of the view, not in the bottom...

I have been looking for the solution but I have not found it in the documentation.. Anyone knows how to change the place of the banner?

Thanks in advance.


Solution

  • Well the only thing that I needed to do was to change the func bannerViewDidLoadAd this way:

    func bannerViewDidLoadAd(banner: ADBannerView!) {
    
            adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
            adBannerView.frame = CGRectOffset(adBannerView.frame,0.0,0.0)
            adBannerView.hidden = false
    
    
        }