【问题标题】:How to get a BannerAd at the bottom of the screen. Xcode 7.0.1如何在屏幕底部获取 BannerAd。 Xcode 7.0.1
【发布时间】:2015-10-14 04:53:49
【问题描述】:

嘿,这是我用于 Xcode 6.4 的代码,但是当我转到 Xcode 7 时出现错误。所以一开始我只是删除了 ConstantsH 和 V。这消除了错误,但后来我查看应用程序,横幅不再位于屏幕底部,现在位于顶部。如何在 Xcode 7 中将其改回?提前致谢。

代码:

class GameViewController: UIViewController, ADBannerViewDelegate{

var bannerAd = ADBannerView(adType: ADAdType.Banner)


override func viewDidLoad() {
    super.viewDidLoad()
    bannerAd.delegate = self
    self.view.addSubview(bannerAd)

    let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("|[bannerAd]|", options: nil, metrics: nil, views: ["bannerAd":bannerAd])
    let constraintsV = NSLayoutConstraint.constraintsWithVisualFormat("V:[bannerAd(50)]|", options: nil, metrics: nil, views: ["bannerAd":bannerAd])
    self.view.addConstraints(constraintsH)
    self.view.addConstraints(constraintsV)

完整文件如下:-----------------

  import StoreKit
  import SpriteKit
  import GameKit
  import iAd




class GameViewController: UIViewController, ADBannerViewDelegate{

var bannerAd = ADBannerView(adType: ADAdType.Banner)


override func viewDidLoad() {
    super.viewDidLoad()
    bannerAd.delegate = self
    self.view.addSubview(bannerAd)

    let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("|[bannerAd]|", options: nil, metrics: nil, views: ["bannerAd":bannerAd])
    let constraintsV = NSLayoutConstraint.constraintsWithVisualFormat("V:[bannerAd(50)]|", options: nil, metrics: nil, views: ["bannerAd":bannerAd])
    self.view.addConstraints(constraintsH)
    self.view.addConstraints(constraintsV)






    func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController!)
    {
        gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)
    }




    let localPlayer = GKLocalPlayer()

    localPlayer.authenticateHandler = {(viewController, error) -> Void in

        if (viewController != nil) {
            let vc: UIViewController = self.view!.window!.rootViewController!
            vc.presentViewController(viewController!, animated: true, completion: nil)
        }

        else {
            print((GKLocalPlayer.localPlayer().authenticated))

        }
    }





}
override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    let scene = GameScene()
    let sKView = self.view! as! SKView
        sKView.ignoresSiblingOrder = true
        scene.size = sKView.bounds.size
        scene.scaleMode = .AspectFill
        let reveal = SKTransition.fadeWithDuration(0.45)
        sKView.presentScene(scene, transition: reveal)






}



override func shouldAutorotate() -> Bool {
    if (UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft ||
        UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeRight ||
        UIDevice.currentDevice().orientation == UIDeviceOrientation.Unknown) {
            return false;
    }
    else {
        return true;
    }
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Release any cached data, images, etc that aren't in use.
}

override func prefersStatusBarHidden() -> Bool {
    return true
}

func bannerViewWillLoadAd(banner: ADBannerView!) {
    NSLog("bannerViewWillLoadAd")
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    NSLog("bannerViewDidLoadAd")
    self.bannerAd.hidden = false//now show banner as ad is loaded
}

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

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

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    NSLog("bannerView")
    self.bannerAd.hidden = true
 }
}

【问题讨论】:

    标签: ios xcode adbannerview


    【解决方案1】:

    这就是你的做法

    bannerAd.center = CGPoint(x: bannerAd.center.x, y: view.bounds.size.height - bannerAd.frame.size.height * 0.05)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 2017-06-10
      • 2016-01-27
      • 1970-01-01
      相关资源
      最近更新 更多