ios - 如何阻止 iAds 在 xcode 中扭曲 SKScene?

标签 ios objective-c xcode ios7 iad

因此,我已将 iAds 添加到我的应用程序中,而且我的操作非常简单。通过将 iAds 导入 ViewController.h 并将以下代码放入 ViewController.m 文件:

self.canDisplayBannerAds = YES;

但是,当我加载加载屏幕时,这会起作用。所有图像和 Sprite 都变短了。

有什么方法可以将添加叠加在 SKScene 之上?所以这不会影响下面的元素 - 所以它会停止挤压?

另外,有没有办法只在某些 SKScenes 中或当 BOOL 从 YES 更改为 NO 时才运行横幅广告?

已更新

我项目中的代码:

#import "XYZViewController.h"
#import "XYZMenuScene.h"
#import <iAd/iAd.h>

@implementation XYZViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view.
    SKView * skView = (SKView *)self.view;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;

    // Create and configure the scene.
    SKScene * scene = [XYZMenuScene sceneWithSize:skView.bounds.size];
    scene.scaleMode = SKSceneScaleModeAspectFill;

    //iAds Enabled
    self.canDisplayBannerAds = YES;

    // Present the scene.
    [skView presentScene:scene];
}

这就是我在 iAd 方面的全部内容。它使整个场景向上推,为广告横幅腾出空间。我希望它只是在场景上方而不是插入任何东西。所以它覆盖,而不是推送。

最佳答案

要覆盖,您可以将横幅的 Z 位置设置为高于其余内容,默认情况下为 0。

例如:

    banner.layer.zPosition=2;

但我相信 iAd 框架内置了您可以重写的方法,以控制广告何时必须显示以及何时不应该显示,并为您提供更多控制权。 当广告可用时调用特定方法,就像你说的那样,你让广告仅在 bool 值为 1 或 0 时出现。

例如:

  - (void)bannerViewDidLoadAd:(ADBannerView *)banner
   {

  if(showADS==1)
  {
if (!self.bannerIsVisible)
{  
    [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
 // Assumes the banner view is just off the bottom of the screen.
    banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
    [UIView commitAnimations];
    self.bannerIsVisible = YES;
}
}
 else
  {NSlog(@"No ads");}

}

查看苹果的相关文档,它们真的很有帮助 https://developer.apple.com/library/ios/documentation/userexperience/Conceptual/iAd_Guide/WorkingwithBannerViews/WorkingwithBannerViews.html

但是让我们举一个完整的例子。 横幅实例仅在您的 iAd 方法中可用,在它们之外不可用。 在您看来确实加载了方法:

    - (void)viewDidLoad

    { 

     self.canDisplayBannerAds=YES;

     }    

该方法在广告加载时调用,在该方法中指定广告的位置

    - (void)bannerViewDidLoadAd:(ADBannerView *)banner
      {
         banner.layer.zPosition=2;
        /*do all the additional like checking is the boolean is 1 or 0 etc.*/ 

      }

如果您正在使用 iAd 和 sprite kit,则需要从场景类调用 View Controller 中的方法来完成所有广告工作。

假设您的 View Controller 中有一个名为 checkAD 的方法,用于检查广告是否应显示等。

您可以使用此代码从场景类中调用此方法

if([self.delegate respondsToSelector:@selector(checkAD)]){

    [self.delegate checkAD];
}

关于ios - 如何阻止 iAds 在 xcode 中扭曲 SKScene?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24906531/

相关文章:

ios - Swift 以编程方式设置 View 约束错误日志

ios - xcode 构建中的不同参数

ios - 使用 AVAudioRecorder 和 AVAudioSessionCategoryPlayAndRecord 忽略麦克风输入

iphone - 从 Unity3d 中的 iphone 文档目录加载图像

ios - UISystemGateGestureRecognizer 和屏幕底部附近的延迟点击

ios - UIView 作为 UIImageView 的父级

objective-c - OS X 上的 3D CAD 图形框架 - 有建议吗?

ios - sleep 模式与通知中心打开

ios - 使用来自 url 的 uitableview 缓存 UIImage

ios - 已辞职的 ipa 在 iOS 8 中安装但未在 iOS 9+ 中安装