Hey This is the code I used for Xcode 6.4 but when I go to Xcode 7 there's an error. So at first I just deleted the ConstantsH and V. That got rid of the errors but then I look at the app and the banner is no longer at the bottom of the scree now its at the top. How do I change that back in Xcode 7? Thanks in advance.
Code:
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)
Full File Below:-----------------
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
}
}
This is how you do it
bannerAd.center = CGPoint(x: bannerAd.center.x, y: view.bounds.size.height - bannerAd.frame.size.height * 0.05)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.