以编程方式添加GADBannerView [英] Add GADBannerView Programmatically

查看:312
本文介绍了以编程方式添加GADBannerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个类作为AdMobViewController,我用来添加此类的横幅。横幅创建但视图中的其他对象不向上滚动。我如何以编程方式向上滚动视图中的所有对象。

I created a class as AdMobViewController and I use to add banner this class. Banner create but other objects in view don't scroll up. How I do programmatically scroll up all objects in view.

我的AdMobViewController类和方法:

My AdMobViewController class and method:

+ (void)createBanner:(UIViewController *)sender
{
    GADRequest *request = [GADRequest request];
    request.testing = YES;
    request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];

    GADBannerView *bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    bannerView.adUnitID = @"ca-app-pub-123456";
    bannerView.rootViewController = (id)self;
    bannerView.delegate = (id<GADBannerViewDelegate>)self;
    bannerView.frame = CGRectMake(0, 518, 320, 50);

    [bannerView loadRequest:request];

    [sender.view addSubview:bannerView];
}

我用来创建横幅:

[AdMobViewController createBanner:self];


推荐答案

嗯,我认为你需要考虑多个事项:

Well I think you have multiple things to consider:


  1. [sender.view addSubview:bannerView] 不会移动其他视图,
    而不是将横幅视图直接放在视图
    层次结构的顶部。

  1. [sender.view addSubview:bannerView] does not move other views, instead you are placing the banner view directly on top of the view hierarchy.

广告是异步加载的,所以你应该实现 GADBannerView 的委托
方法,以显示和隐藏广告视图。

Ads are loaded asynchronously, so you should implement the delegate methods of GADBannerView for showing and hiding the ad view.

如果你真的想要移动其他视图你应该使用一些
类型的容器视图来包含除
横幅之外的所有其他内容。如果您收到广告,则可以轻松移动容器视图
(或缩小它),并在
主视图中的某个位置显示横幅广告视图。

If you really want to move other views around you should use some kind of container view to include all other content except your banner. If you receive an ad you can easily move the container view (or shrink it) and display your banner view on some location in your main view.

干杯

这篇关于以编程方式添加GADBannerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆