【问题标题】:How to stop iAds from skewing the SKScene in xcode?如何阻止 iAds 在 xcode 中扭曲 SKScene?
【发布时间】:2014-07-23 09:17:39
【问题描述】:

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

self.canDisplayBannerAds = YES;

但是,当我添加加载时,屏幕会被挤压。所有图像和精灵都变短了。

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

另外,有没有办法让横幅广告只在某些 SKScene 中或当 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 方面的全部内容。它使整个场景向上推,为广告横幅腾出空间。我希望它只是在场景中而不是推动任何东西。所以它覆盖,而不是推动。

【问题讨论】:

    标签: ios objective-c xcode ios7 iad


    【解决方案1】:

    要叠加,您可以将横幅的 Z 位置设置为高于其余内容,默认为 0。

    例如:

        banner.layer.zPosition=2;
    

    但我相信 iAd 框架已内置方法,您可以覆盖该方法来控制广告何时必须显示以及何时不应显示,并为您提供更多控制权。 广告可用时调用特定方法,就像您说的那样,您只在布尔值为 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,则需要从场景类调用视图控制器中的方法来完成所有广告工作。

    假设您的视图控制器中有一个名为 checkAD 的方法,用于检查广告是否应该显示等。

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

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

    【讨论】:

    • 第一个问题,banner变量是怎么得到的? @Prithiv
    • 横幅实例仅在 iAd 方法中起作用,这是自动为您完成的。一件事是它只适用于 iAd 方法,您可以在想要显示广告的时间设置位置
    • 我的意思是 zPosition。我必须创建横幅变量吗?
    • 我说的是 zPosition。在 iad 方法中设置 zPosition。
    • 我不明白?我把 self.canDisplayBannerAds = YES;在 ViewController.m 文件中
    【解决方案2】:

    在容器视图中添加 SKSCene 可能会有所帮助。根据我的经验,当通过 canDisplayBannerAds 添加 iAd 时,任何 Apple 的 UIViewController 子类都会做一些奇怪的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-02
      • 2012-03-31
      • 1970-01-01
      • 2012-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多