gpt4 book ai didi

swift - iAd Interstitial 触摸激活场景按钮。 swift

转载 作者:行者123 更新时间:2023-11-28 09:29:56 27 4
gpt4 key购买 nike

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

最佳答案

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

关于swift - iAd Interstitial 触摸激活场景按钮。 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29402197/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com