如何为iAdbannerView制作关闭按钮



谁能帮助我在iAdbannerview的关闭按钮,这将pe上方的横幅在右上方,以便如果人们不想看到广告,他/她可以点击关闭按钮来隐藏广告。帮助我在编码下面是链接打开截图我的视图控制器https://drive.google.com/file/d/0B2z_d4wEKPEFTHVNY1AycVdTNTQ/view?usp=sharing

  @IBOutlet var adBannerView: ADBannerView?
 override func viewDidLoad() {
super.viewDidLoad()


self.canDisplayBannerAds = true
self.adBannerView!.delegate = self
self.adBannerView!.hidden = true //hide until ad loaded
 }
func bannerViewWillLoadAd(banner: ADBannerView!) {
  }
func bannerViewDidLoadAd(banner: ADBannerView!) {
self.adBannerView?.hidden = false
 }
func bannerViewActionDidFinish(banner: ADBannerView!) {
  }
   func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplicationwillLeave: Bool) -> Bool {
return true
}
 func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error:NSError!) {
self.adBannerView!.hidden = true
          }

这是通过编程实现的:

adBannerView下创建UIButton:
var button = UIButton()

viewDidLoad中实例化按钮并将其放置在adBannerView的右上方:

button.frame = CGRectMake(self.view.center.x + 150, self.view.frame.size.height - 66, 10, 10)
button.setBackgroundImage(UIImage(named: "Yourclosebuttonimagename"), forState: UIControlState.Normal)
self.view.addSubview(button)
button.addTarget(self, action: "hideAd:", forControlEvents: UIControlEvents.TouchUpInside)

函数将被称为hideAd:

func hideAd(sender:AnyObject){
self.adBannerView.hidden = true
self.button.hidden = true
// or do 
self.button.removeFromSuperview()
self.adBannerView.removeFromSuperview()
}

我建议您删除self.canDisplayBannerAds = true,因为self.adBannerView!.delegate = self足以运行iAd。

相关内容

  • 没有找到相关文章

最新更新