towerthepower
towerthepower

Reputation: 31

ADBannerView takes more space than normal

I have something strange in my app and since I'm a beginner with ADBannerView I hope somebody could help me.

I already configured in appDelegate.swift the methods to create and manage the ADBannerView, in my view I add this code:

    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
override func viewDidLoad() {
        super.viewDidLoad()


        appDelegate.adBannerView.center = CGPoint(x: view.frame.midX, y:  view.frame.height - appDelegate.adBannerView.frame.height / 2)

        view.addSubview(appDelegate.adBannerView)

        self.canDisplayBannerAds = true

    }

Then iAd is correctly shown in my view but also a 49px empty bar over it (the white one). How can I delete it? Is it part of the iAd? Any idea?

Click to see the picture

Thank you in advance!

Upvotes: 1

Views: 49

Answers (2)

towerthepower
towerthepower

Reputation: 31

Thank you pbush25, I found the solution. I post it if others need it.

In appDelegate.swift

class AppDelegate: UIResponder, UIApplicationDelegate, ADBannerViewDelegate {

var window: UIWindow?
var adBannerView = ADBannerView()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    adBannerView.delegate = self
    adBannerView.hidden = true
    return true
}


func bannerViewDidLoadAd(banner: ADBannerView!) {
    print("bannerViewDidLoadAd")
    adBannerView.hidden = false
}

func bannerViewActionDidFinish(banner: ADBannerView!) {
    print("bannerViewActionDidFinish")
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    print("didFailToReceiveAdWithError: \(error)")
    adBannerView.hidden = true
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
    print("bannerViewWillLoadAd")
}

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

and in every view I want to show iAd

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
override func viewDidLoad() {
    super.viewDidLoad()
    self.defaultLoad()
}

override func viewWillAppear(animated: Bool) {
    self.defaultLoad()
}
override func viewWillDisappear(animated: Bool) {
    appDelegate.adBannerView.delegate = nil
    view.removeFromSuperview()
}

func defaultLoad(){
    appDelegate.adBannerView.frame = CGRectMake(0, (view.frame.height) - 99, (view.frame.size.width), 50) // 50(banner)+49(tab bar)
    appDelegate.adBannerView.delegate = appDelegate
    super.view.addSubview(appDelegate.adBannerView)
    super.view.bringSubviewToFront(appDelegate.adBannerView)
    super.view.layoutIfNeeded()
    super.canDisplayBannerAds = true
}

Upvotes: 2

pbush25
pbush25

Reputation: 5248

When you instantiate your ADBannerView you should probably instantiate it with a frame:

var adBannerView = ADBannerView(frame: CGRectMake(0, (self.window?.frame.height)! - 50, (self.window?.frame.size.width)!, 50))

And then it should always be at that part of the whole Window of your app. Thus in your viewDidLoad you don't need to set the center, you'll just need to self.view.addSubview(adBannerView) and then probably self.view.bringSubviewToFront(adBannerView)

Upvotes: 0

Related Questions