简体   繁体   English

Spritekit(Swift)中的ADBannerView。 我不能把它放在视图的底部

[英]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: 在我的GameViewControler.swift我找到了放置iad横幅的方法:

...
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. 提前致谢。

Well the only thing that I needed to do was to change the func bannerViewDidLoadAd this way: 好吧,我唯一需要做的就是以这种方式更改func bannerViewDidLoadAd

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


    }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM