ADBannerView占用的空间比平时多

时间:2015-10-28 15:55:00

标签: ios swift adbannerview

我的应用程序中有一些奇怪的东西,因为我是ADBannerView的初学者,我希望有人可以帮助我。

我已经在appDelegate.swift中配置了创建和管理ADBannerView的方法,在我的视图中我添加了这段代码:

    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

    }

然后iAd在我的视图中正确显示,但在它上面还有一个49px空条(白色)。我该如何删除它?它是iAd的一部分吗?有什么想法吗?

Click to see the picture

提前谢谢!

2 个答案:

答案 0 :(得分:2)

谢谢pbush25,我找到了解决方案。如果其他人需要,我会发布它。

在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
}

并且在每个视图中我都要展示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
}

答案 1 :(得分:0)

当您实例化ADBannerView时,您应该使用框架实例化它:

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

然后它应该始终位于应用的整个Window的那一部分。因此,在viewDidLoad您不需要设置中心,您只需要self.view.addSubview(adBannerView)然后可能self.view.bringSubviewToFront(adBannerView)