所以我已经在我的应用程序中实现了iAd,导入了框架并将其导入我的View Controller并添加了委托以及所有这些。当我运行我的应用程序时,我确实看到了它,但是,我有一个标签栏(我没有使用标签栏控制器,如果这很重要)并且我想在标签栏上面有iAd,因为目前我在它下面得到它标签栏并觉得这对用户体验不利,而Apple的文档也提到将其直接放在标签栏(https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/iAdRichMediaAds.html)上方。我一直在玩它,但没有任何工作,并想知道是否有人对我下面发布的代码有任何建议。感谢。
var bannerView: ADBannerView!
@IBOutlet weak var tabBar: UITabBar!
override func viewDidLoad() {
super.viewDidLoad()
self.canDisplayBannerAds = true
bannerView = ADBannerView(frame: CGRectZero)
bannerView.frame = CGRectMake(0, self.view.frame.size.height - self.tabBar.frame.size.height - bannerView.frame.size.height, self.view.frame.size.width, bannerView.frame.size.height)
bannerView.alpha = 0.0
bannerView.delegate = self
self.view!.addSubview(bannerView)
func bannerViewDidLoadAd(banner: ADBannerView!) {
print("bannerViewDidLoadAd")
bannerView.hidden = false
}
func bannerView(banner: ADBannerView, didFailToReceiveAdWithError error: NSError) {
UIView.animateWithDuration(0.5, animations: {banner.alpha = 1.0})
UIView.commitAnimations()
bannerView.hidden = true
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
答案 0 :(得分:-1)
首先,这条线毫无意义
bannerView.frame = CGRectMake(0, self.view.frame.size.height - self.tabBar.frame.size.height - bannerView.frame.size.height, self.view.frame.size.width, bannerView.frame.size.height)
你正在设置" bannerView.frame"使用" bannerView.frame"的属性你刚刚用#C; CGRectZero" ????
在做任何事之前,只需阅读: https://developer.apple.com/news/?id=01152016a