我想知道是否有人可以帮助我。我正在尝试以横向模式创建iAd横幅。到目前为止我使用了这段代码。它仍然显示iAd横幅具有相同的高度和宽度,就像它以纵向模式显示一样。横幅是居中的。任何帮助将非常感激。
var adBannerView: ADBannerView!
let screenBounds: CGRect = UIScreen.mainScreen().bounds
override func viewDidLoad() {
super.viewDidLoad()
// Presenting scene without using GameScene.sks
let skView = self.view as SKView
let myScene = Menu(size: skView.frame.size)
skView.presentScene(myScene)
loadAds()
print("height: \(screenBounds.height), width: \(screenBounds.width)")
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
println("Leaving app to the Ad")
return true
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
adBannerView.frame = CGRectOffset(adBannerView.frame,0.0,0.0)
adBannerView.hidden = false
println("Displaying the Ad")
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height + view.bounds.size.height)
println("Ad is not available")
}
func loadAds() {
adBannerView = ADBannerView(frame: CGRectMake(0, 0, 50, screenBounds.width))
adBannerView.center = CGPoint(x: screenBounds.width/2, y: screenBounds.height-adBannerView.frame.height)
adBannerView.delegate = self
adBannerView.hidden = true
view.addSubview(adBannerView)
}
答案 0 :(得分:0)
你使用Main.Storyboard吗?因为您只需调整故事板上横幅视图的大小。
答案 1 :(得分:0)
这对我有用:
var UIiAd: ADBannerView = ADBannerView()
override func viewWillAppear(animated: Bool) {
UIiAd.setTranslatesAutoresizingMaskIntoConstraints(false)
UIiAd.delegate = self
self.view.addSubview(UIiAd)
let viewsDictionary = ["bannerView":UIiAd]
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[bannerView]|", options: .allZeros, metrics: nil, views: viewsDictionary))
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[bannerView]|", options: .allZeros, metrics: nil, views: viewsDictionary))
}