如果未在Swift中加载奖励广告,如何隐藏UIButton?

时间:2019-05-09 21:11:16

标签: swift sprite-kit uibutton admob ads

我目前正在spritekit上将广告整合到我的游戏中,我有一个按钮,如果单击该按钮,用户可以获得免费的硬币来观看广告。但是,此操作仅在广告加载后运行,问题在于按钮仍然存在。我希望在广告尚未加载时隐藏按钮,并在广告加载后显示。我从视图控制器中删除了无关的代码。

import UIKit
import SpriteKit
import GameplayKit
import GoogleMobileAds

class GameViewController: UIViewController, GADBannerViewDelegate, GADRewardBasedVideoAdDelegate {

    @IBOutlet weak var bannerView: GADBannerView!

   @IBOutlet weak var playRewardAd: UIButton!

        override func viewDidLoad() {

            super.viewDidLoad()

            GADRewardBasedVideoAd.sharedInstance().load(GADRequest(),
                                                    withAdUnitID: "ca-app-pub-3940256099942544/1712485313")

            GADRewardBasedVideoAd.sharedInstance().delegate = self

            bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
            bannerView.rootViewController = self
            bannerView.load(GADRequest())

    @IBAction func playVideoAd(_ sender: Any) {

        if GADRewardBasedVideoAd.sharedInstance().isReady == true         {
            GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self)
        }        
}

    func rewardBasedVideoAdDidClose(_ rewardBasedVideoAd: GADRewardBasedVideoAd) {
        GADRewardBasedVideoAd.sharedInstance().load(GADRequest(),
                                                withAdUnitID: "ca-app-pub-3940256099942544/1712485313")

    }

    func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd,
                            didRewardUserWith reward: GADAdReward) {
        coinNumber = coinNumber + 100
        defaults.set(coinNumber, forKey: "coinsSaved")
        coinLabel.text = "\(coinNumber)"
    }
}

0 个答案:

没有答案