iAd in xcode 6 with Swift

你说的曾经没有我的故事 提交于 2019-11-27 07:55:01

This is how I did it, possibly not all of it is necessary.

I did not use the banner in the Storyboard, so the IBOutlet is not necessary.

Also, if you manually create a banner, you do not need to set self.canDisplayBannerAds

This function (ported from ObjC) is how I display the ads.

func loadAds(){
  adBannerView = ADBannerView(frame: CGRect.zeroRect)
  adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
  adBannerView.delegate = self
  adBannerView.hidden = true
  view.addSubview(adBannerView)
}

This is called in viewDidLoad. Then, in the didLoadAd delegate method, I set adBannerView.hidden = false and in didFailToReceiveAdWithError, adBannerView.hidden = true

I think hidden is better than alpha in this situation, as it feels more natural. I believe (but am not sure) that when hidden, the view is not drawn at all by the GPU, while with an alpha of 0, it is still drawn, but made invisible (correct me if I am wrong).

This is my setup, and it worked for me, so hopefully it will work in your case too!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!