集成 iAd 后 Sprite Kit SKScene 尺寸错误或根本不工作

Sprite Kit SKScene with wrong size after integrating iAd or not working at all

我正在尝试将 iAd 集成到 Sprite Kit 游戏中。

当我在添加游戏场景之前设置 "canDisplayBannerAds = true" 时,会显示横幅添加但 gameScene 不起作用:

override func viewDidLoad() {
    super.viewDidLoad()

    canDisplayBannerAds = true

    // Configure de main view
    if let skView = view as? SKView {

        // Create and configure scene
        scene = GameScene(size: skView.bounds.size)
        scene!.scaleMode = .AspectFill

        // Show the scene
        skView.presentScene(scene!)
    }
}

当我设置 "canDisplayBannerAds = true" 添加 SKScene 后,显示 iAd 并且游戏场景现在可以正常工作,但尺寸错误,大于添加横幅后留下的屏幕。

override func viewDidLoad() {
    super.viewDidLoad()

    // Configure de main view
    if let skView = view as? SKView {
        skView.showsFPS = true

        // Create and configure scene
        scene = MarketGameScene(size: skView.bounds.size)
        scene!.scaleMode = .AspectFill
        scene!.marketGameViewController = self

        // Show the scene
        skView.presentScene(scene!)
    }

    canDisplayBannerAds = NSUserDefaults.standardUserDefaults().boolForKey(UserDefaultsKey.ShowAds)
}

我错过了什么? 谢谢

这里有一些适用于你的工作代码,我刚刚工作过。这甚至不需要 self.candisplaybannerads = true 因为我对此有一些问题。广告会根据屏幕尺寸自动改变尺寸,位于屏幕底部。要隐藏和显示广告,请使用

AdBanner.hidden = true/false

......

import iAd

class viewController: UIViewController, ADBannerViewDelegate {

var AdBanner = ADBannerView()

override func viewDidLoad() {
    super.viewDidLoad()

        /* Ad Banner Settings */

        AdBanner = ADBannerView()
        AdBanner.frame = CGRectZero
        AdBanner.delegate = self
        self.AdBanner.frame = CGRectMake(0, self.view.frame.size.height-self.AdBanner.frame.size.height, self.AdBanner.frame.size.width, self.AdBanner.frame.size.height)
        AdBanner.backgroundColor = UIColor.clearColor()
        self.view .addSubview(AdBanner)

}

/* All iAd Functions */

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
/* whatever you need */
    return true
}

func bannerViewActionDidFinish(banner: ADBannerView!) {
/* whatever you need */
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    AdBanner.hidden = false
}


func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    NSLog("Error Loading Ad")
/* whatever you need */
    AdBanner.hidden = true
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
/* whatever you need */
}