如何为 iAdbannerView 制作关闭按钮

How to make close button for iAdbannerView

任何人都可以帮助我为 iAdbannerview 制作一个关闭按钮,该按钮将放置在右上角的横幅上方,这样如果人们不想看到广告 he/she 可以点击关闭按钮来隐藏ads.Help我在编码下面是link打开我的截图viewcontrollerhttps://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。

祝你好运!