简体   繁体   English

ADBannerView比正常占用更多空间

[英]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. 我的应用程序中有一些奇怪的东西,由于我是ADBannerView的初学者,我希望有人可以帮助我。

I already configured in appDelegate.swift the methods to create and manage the ADBannerView, in my view I add this code: 我已经在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

    }

Then iAd is correctly shown in my view but also a 49px empty bar over it (the white one). 然后,iAd会正确显示在我的视图中,但它上方还有一个49px的空白栏(白色)。 How can I delete it? 如何删除? Is it part of the iAd? 它是iAd的一部分吗? Any idea? 任何想法?

Click to see the picture 点击查看图片

Thank you in advance! 先感谢您!

Thank you pbush25, I found the solution. 谢谢pbush25,我找到了解决方案。 I post it if others need it. 如果其他人需要,我会发布它。

In appDelegate.swift 在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 在每个视图中我都想展示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
}

When you instantiate your ADBannerView you should probably instantiate it with a frame: 实例化ADBannerView ,可能应使用框架实例化它:

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. 然后,它应该始终位于应用程序整个Window的该部分。 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) 因此,在viewDidLoad您不需要设置中心,只需要self.view.addSubview(adBannerView) ,然后可能是self.view.bringSubviewToFront(adBannerView)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS / Swift:超过10个ADBannerView实例 - iOS/Swift: more than 10 instances of ADBannerView 目标c-Iad警告:超过10个ADBannerView实例 - Objective c - Iad WARNING: More than 10 instances of ADBannerView 为什么xcode中的图像在运行时占用的空间比实际大小多50倍 - Why does image in xcode takes up 50x more space during runtime than the actual size Swift iAd-超过10个ADBannerView警告和CGAffineTransformInvert实例:奇异矩阵输出 - Swift iAd - More than 10 instances of ADBannerView warning and CGAffineTransformInvert: singular matrix output sleep(1)或sleepForTimeInterval 1需要超过1秒才能唤醒 - sleep(1) or sleepForTimeInterval 1 takes more than 1 second to wake 该算法比预期花费更多时间 - This algorithm takes more time than expected UITableView-cellForRowAtIndexPath耗时超过半秒 - UITableView - cellForRowAtIndexPath takes more than half a second UIImage占用的内存比NSData多得多 - UIImage takes up much more memory than its NSData 从字符串中去除前导、尾随和 1 个以上的空格 - Strip leading, trailing and more than 1 space from String iOS 8 textDocumentProxy-能够删除多个空格? - iOS 8 textDocumentProxy - able to delete more than one space?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM