【问题标题】:Hiding iAd banner in gameplay scene?在游戏场景中隐藏 iAd 横幅?
【发布时间】:2014-03-21 03:48:37
【问题描述】:

在我的游戏中,我添加了 iAd。

我想添加一些代码,告诉应用仅在场景为 GameOverSceneNewGameScene 时加载横幅,并让游戏场景远离任何广告。

我该怎么做? (对 obj-c 来说相当新)。

【问题讨论】:

  • 如何在 .h 文件中声明这个? @霍斯特
  • 你有一个ADBannerView,你可以使用辅助视图。按下 control 并将广告视图拖到 .h 文件中,xcode 将为您完成剩下的工作。

标签: ios objective-c sprite-kit iad skscene


【解决方案1】:

当您将ADBannerView 的 alpha 设置为 0 时,它会自动被禁用,并且不会显示任何广告。所以,当调用该方法开始游戏时,还应该加上这段代码:

[myAdBanner setAlpha:0];

然后,当用户返回主菜单,或退出他们玩游戏的部分时,您应该添加以下代码:

[myAdBanner setAlpha:1];

如果您想在禁用或启用横幅视图时制作漂亮的动画,您可以这样做:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:(duration in seconds)];
[banner setAlpha:(0 to disable, 1 to enable)];
[UIView commitAnimations];

使用所有这些代码,使用动画使横幅视图淡入淡出的示例是:

- (IBAction)startGame{
    //user starts the game
    [UIView beginAnimations:nil context:NULL];//initiate the animation
    [UIView setAnimationDuration:1];//make an animation 1 second long
    [banner setAlpha:0];//disable the ad by making it invisible
    [UIView commitAnimations];//do the animation above
}

- (IBAction)endGame{
    //user wins, loose, or ends the game
    [UIView beginAnimations:nil context:NULL];//initiate the animation
    [UIView setAnimationDuration:1];//make an animation 1 second long
    [banner setAlpha:1];//enable the ad by making it visible
    [UIView commitAnimations];//do the animation above
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多