Search code examples
iosswiftiad

Display an iAd banner in landscape in swift & spritekit


Firstly ive looked through stack overflow for hours and none of the similar topics work for what im trying to do.

i have iads showing however its the size of an iad which would display in portrait mode, somehow i need one that works for landscape, here is the code that i have and i have changed the numbers and messed around with the code but it just wont work for me.

This code is in my gameviewcontroller:

    var SH = UIScreen.mainScreen().bounds.height
let transition = SKTransition.fadeWithDuration(1)
var UIiAd: ADBannerView = ADBannerView()

override func viewWillAppear(animated: Bool) {
    var BV = UIiAd.bounds.height

    UIiAd.delegate = self
    UIiAd.frame = CGRectMake(0, SH + BV, 0, 0)
    self.view.addSubview(UIiAd)
}

override func viewWillDisappear(animated: Bool) {
    UIiAd.delegate = nil
    UIiAd.removeFromSuperview()
}

func bannerViewDidLoadAd(banner: ADBannerView!) {

    var BV = UIiAd.bounds.height
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(0) // Time it takes the animation to complete
    UIiAd.alpha = 1 // Fade in the animation
    UIView.commitAnimations()
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(0)
    UIiAd.alpha = 0
    UIView.commitAnimations()
}

func showBannerAd() {
    UIiAd.hidden = false
    var BV = UIiAd.bounds.height
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(0) // Time it takes the animation to complete
    UIiAd.frame = CGRectMake(0, SH - BV, 0, 0) // End position of the animation

    UIView.commitAnimations()
}

func hideBannerAd() {
    UIiAd.hidden = true
    var BV = UIiAd.bounds.height

    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(0) // Time it takes the animation to complete
    UIiAd.frame = CGRectMake(0, SH + BV, 0, 0) // End position of the animation
    UIView.commitAnimations()
}

i have attached a screen shot to show the problem i am having, if anyone can help it would be great!

iad landscape problem

thanks.


Solution

  • try this and tell me if its work.

      let screenBounds: CGRect = UIScreen.mainScreen().bounds
    
            var adBannerView: ADBannerView  
            adBannerView = ADBannerView(frame: CGRectMake(0, 0, 50, screenBounds.width))
            adBannerView.center = CGPoint(x: screenBounds.width/2, y: screenBounds.height-adBannerView.frame.height)
            adBannerView.delegate = self
            adBannerView.hidden = true
            view.addSubview(adBannerView)