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

标签 swift iad

我在 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/

相关文章:

ios - 更改 View 后 UITabBar iAd 横幅未正确加载

ios - iAd 框架在 iPhone 上返回错误的高度

ios - 如何在 swift 5 中仅获取所选行的 CoreData 结果?

swift - 使用 SwiftCharts 创建图表

ios - 解析查询结果未添加(附加)到 iOS Swift 中的本地数组

ios - 在 Swift 中带有 header 的 URLRequest

ios - 将图像添加到警报 View

ios - 主详细信息项目模板和 canDisplayBannerAds 不起作用

objective-c - 广告横幅挡住了 UITableView 的底部

ios - iAd 奇怪的消息 - iPhone