Yasin Uğur Yıldız Yasin Uğur Yıldız - 1 year ago 352
Objective-C Question

Add GADBannerView Programmatically

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.

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];

And I use for creating banner:

[AdMobViewController createBanner:self];

Answer Source

Well I think you have multiple things to consider:

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

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

  3. 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.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download