如何在屏幕底部获取BannerAd。 Xcode 7.0.1

时间:2015-10-14 04:53:49

标签: ios xcode adbannerview

嘿这是我用于Xcode 6.4的代码但是当我去Xcode 7时出现了错误。所以起初我刚刚删除了ConstantsH和V.这样就摆脱了错误,但后来我看了应用程序,横幅不再是scree的底部,现在它位于顶部。如何在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
 }
}

1 个答案:

答案 0 :(得分:0)

你就是这样做的

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