首先,我看了几个小时的堆栈溢出,没有类似的主题适用于我想要做的事情。
我有iad显示其iad的大小将以纵向模式显示,不知何故我需要一个适用于横向的代码,这里是我拥有的代码,我已经更改了数字并且与代码混淆但是它只是不适合我。
此代码位于我的gameviewcontroller中:
var SH = UIScreen.mainScreen().bounds.height
let transition = SKTransition.fadeWithDuration(1)
var UIiAd: ADBannerView = ADBannerView()
override func viewWillAppear(animated: Bool) {
var BV = UIiAd.bounds.height
UIiAd.delegate = self
UIiAd.frame = CGRectMake(0, SH + BV, 0, 0)
self.view.addSubview(UIiAd)
}
override func viewWillDisappear(animated: Bool) {
UIiAd.delegate = nil
UIiAd.removeFromSuperview()
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
var BV = UIiAd.bounds.height
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0) // Time it takes the animation to complete
UIiAd.alpha = 1 // Fade in the animation
UIView.commitAnimations()
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0)
UIiAd.alpha = 0
UIView.commitAnimations()
}
func showBannerAd() {
UIiAd.hidden = false
var BV = UIiAd.bounds.height
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0) // Time it takes the animation to complete
UIiAd.frame = CGRectMake(0, SH - BV, 0, 0) // End position of the animation
UIView.commitAnimations()
}
func hideBannerAd() {
UIiAd.hidden = true
var BV = UIiAd.bounds.height
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(0) // Time it takes the animation to complete
UIiAd.frame = CGRectMake(0, SH + BV, 0, 0) // End position of the animation
UIView.commitAnimations()
}
我附上了一个屏幕截图来显示我遇到的问题,如果有人可以提供帮助就会很棒!
感谢。
答案 0 :(得分:0)
试试这个并告诉我它是否有效。
let screenBounds: CGRect = UIScreen.mainScreen().bounds
var adBannerView: ADBannerView
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)