简体   繁体   English

如何在底部放置AdMob横幅?

[英]How do I place AdMob banner on the bottom?

How can I place the banner form AdMob on the bottom of the screen? 如何将横幅广告形式AdMob放在屏幕底部? I'm using AdMob as a Relay for when the iAd banner fails to load, but the AdMob banner appears at the top of the screen. 当iAd标语无法加载时,我将AdMob用作中继,但AdMob标语显示在屏幕顶部。 I've looked up many ways to do it but non of them work. 我已经找到了许多方法来做到这一点,但是没有一种可以工作。

here is my code: .h 这是我的代码:.h

@interface Class_ScoreViewController : UIViewController <UITextFieldDelegate,ADBannerViewDelegate>
{
    GADBannerView *bannerViewAdMob_;
    ADBannerView *adView;
}
@property (nonatomic,retain) IBOutlet ADBannerView *adView;

.m .m

@synthesize adView;
- (void)bannerViewDidLoadAd:(ADBannerView *)banner{
    NSLog(@"-----------Displaying Ad-------------");
    [adView setHidden:NO];
    bannerViewAdMob_.hidden = YES;
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
    NSLog(@"------------Ad Error-------------");
    [adView setHidden:YES];
    CGSize screenSize = [[UIScreen mainScreen] bounds].size;


    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        if (screenSize.height > 480.0f) {
            //iPhone 5
            bannerViewAdMob_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height- 89 -GAD_SIZE_320x50.height, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];

        }
        else{
            //iPhone 4
            bannerViewAdMob_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-GAD_SIZE_320x50.height, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];


        }
    // Create a view of the standard size at the top of the screen.
    // Available AdSize constants are explained in GADAdSize.h.
    bannerViewAdMob_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];

    // Specify the ad's "unit identifier". This is your AdMob Publisher ID.
    bannerViewAdMob_.adUnitID = @"xxxxxxxxxxxxxxx";

    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    bannerViewAdMob_.rootViewController = self;
    [self.view addSubview:bannerViewAdMob_];

    // Initiate a generic request to load it with an ad.
    [bannerViewAdMob_ loadRequest:[GADRequest request]];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    adView.delegate = self;
    [adView setHidden:YES];
}

you're overriding your variable, check the 您要覆盖变量,请检查

 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        if (screenSize.height > 480.0f)
            bannerViewAdMob_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height- 89 -GAD_SIZE_320x50.height, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
        else
            bannerViewAdMob_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-GAD_SIZE_320x50.height, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];

    bannerViewAdMob_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; // here is you overwrite

to place it properly - set frame/bounds properties after you call initWithAdSize 正确放置-在调用initWithAdSize之后设置框架/边界属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM