【问题标题】:iAd Interstitial touch activates scene button. SwiftiAd Interstitial touch 激活场景按钮。迅速
【发布时间】:2015-07-02 22:02:57
【问题描述】:

我在 SpriteKit 中的 GameOverScene 中实现了 iAd 插页式广告。出于某种原因,当插页式广告弹出时,如果我触摸按钮所在的相同位置,我仍然可以听到按钮点击的声音。如果用户不小心触摸了这个按钮并关闭了插页式广告,场景将变黑,我再也看不到游戏了。有没有办法解决这个问题。

这是我的代码。

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()
}

【问题讨论】:

    标签: swift iad


    【解决方案1】:

    尝试 UIControlEvents.TouchUpInside 与 TouchDown 手指在控件边界内的控件中的触摸事件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多