iAd非页内交互式触摸可激活场景按钮。迅速

时间:2015-04-01 22:49:54

标签: swift iad

我在SpriteKit的GameOverScene中实现了iAd interstitial。出于某种原因,当插页式广告弹出时,如果我触摸与按钮位置相同的位置,我仍然可以听到按钮点击。如果用户意外触摸此按钮并关闭插页式广告,则场景将变为黑色,我再也看不到游戏了。无论如何如何解决这个问题。

这是我的代码。

class GameOverScene: SKScene, ADInterstitialAdDelegate{

var interstitialAd:ADInterstitialAd!
var interstitialAdView: UIView = UIView()
var closeButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
var adBannerView = ADBannerView(frame: CGRect.zeroRect)

func loadInterstitialAd() {
    interstitialAd = ADInterstitialAd()
    interstitialAd.delegate = self
    scene?.paused = true
}

func interstitialAdWillLoad(interstitialAd: ADInterstitialAd!) {

}

func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
    closeButton.frame = CGRectMake(10, 10, 20, 20)
    closeButton.layer.cornerRadius = 10
    closeButton.setTitle("x", forState: .Normal)
    closeButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
    closeButton.backgroundColor = UIColor.whiteColor()
    closeButton.layer.borderColor = UIColor.blackColor().CGColor
    closeButton.layer.borderWidth = 1
    closeButton.addTarget(self, action: "close:", forControlEvents: UIControlEvents.TouchDown)

    interstitialAdView.addSubview(closeButton)

    interstitialAdView = UIView()
    interstitialAdView.frame = self.view!.bounds
    view!.addSubview(interstitialAdView)

    interstitialAd.presentInView(interstitialAdView)
    UIViewController.prepareInterstitialAds()
    println("called after inter ad loads its content ")
}

func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {

    interstitialAdView.removeFromSuperview()
}

func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool {

    return true
}

func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
    println("failed to receive")
    println(error.localizedDescription)

    closeButton.removeFromSuperview()
    interstitialAdView.removeFromSuperview()

}

func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
    interstitialAdView.removeFromSuperview()
    println("user clicked out of ad")
}

override init(size: CGSize) {
    super.init(size: size)
    loadInterstitialAd()
}

1 个答案:

答案 0 :(得分:-2)

尝试UIControlEvents.TouchUpInside与TouchDown 控件中的触摸事件,其中手指在控件的范围内