gpt4 book ai didi

swift - 每次加载 iAd 横幅时,iAd 横幅会抖动/改变场景大小。

转载 作者:搜寻专家 更新时间:2023-11-01 06:23:02 24 4
gpt4 key购买 nike

如果 iAds 横幅不改变场景,我无法将 iAds 实现到游戏中,例如每次加载广告时都会抖动屏幕。请提供解决方案以阻止这种情况发生。

class GameViewController: UIViewController,ADBannerViewDelegate{
@IBOutlet var adBannerView: ADBannerView? //connect in IB connection inspector with your ADBannerView

override func viewDidLoad() {
super.viewDidLoad()

if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true

var defaultsV = NSUserDefaults.standardUserDefaults();
defaultsV.setInteger(0, forKey: "gameOverCount")
defaultsV.setBool(false, forKey: "firstSessionEnded")
defaultsV.synchronize()

//self.adBannerView!.frame = CGRectMake(0, self.view.frame.size.height-self.adBannerView!.frame.size.height, self.adBannerView!.frame.size.width, self.adBannerView!.frame.size.height)




self.adBannerView!.delegate = self
self.adBannerView!.hidden = true //hide until ad loaded

self.canDisplayBannerAds = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
self.adBannerView?.sizeToFit()

/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
skView.presentScene(scene)



}
}

func bannerViewWillLoadAd(banner: ADBannerView!) {
NSLog("bannerViewWillLoadAd")
//self.canDisplayBannerAds = true
self.adBannerView!.hidden = true //hide until ad loaded

self.adBannerView!.frame = CGRectMake(0, self.view.frame.size.height-self.adBannerView!.frame.size.height, self.adBannerView!.frame.size.width, self.adBannerView!.frame.size.height)



}

func bannerViewDidLoadAd(banner: ADBannerView!) {
NSLog("bannerViewDidLoadAd")
self.adBannerView!.frame = CGRectMake(0, self.view.frame.size.height-self.adBannerView!.frame.size.height, self.adBannerView!.frame.size.width, self.adBannerView!.frame.size.height)

self.adBannerView!.hidden = false //now show banner as ad is loaded
//self.canDisplayBannerAds = true


}

func bannerViewActionDidFinish(banner: ADBannerView!) {
NSLog("bannerViewDidLoadAd")


//optional resume paused game code

}

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
NSLog("bannerViewActionShouldBegin")

//optional pause game code

return true
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
NSLog("bannerView")

self.adBannerView!.hidden = true
}

最佳答案

您建议您始终将 canDisplayBannerAds 设置为 false,因为这允许 viewController 在显示广告时调整 View 大小。如果您需要创建另一个 bool 值来确定广告的状态。

//ViewControlller.m
self.canDisplayBannerAds = false

关于swift - 每次加载 iAd 横幅时,iAd 横幅会抖动/改变场景大小。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29886132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com