任何人都可以帮我制作一个关于iAdbannerview的关闭按钮,它将放置在右上方的横幅上方,这样如果有人不想看广告,他/她可以点击关闭按钮来隐藏广告。帮助我在编码中下面是打开我的viewcontroller 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
}
答案 0 :(得分:3)
这是以编程方式执行此操作的方法:
在UIButton
下创建adBannerView
:
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。