簡體   English   中英

如何在底部放置AdMob橫幅?

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

如何將橫幅廣告形式AdMob放在屏幕底部? 當iAd標語無法加載時,我將AdMob用作中繼,但AdMob標語顯示在屏幕頂部。 我已經找到了許多方法來做到這一點,但是沒有一種可以工作。

這是我的代碼:.h

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

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

您要覆蓋變量,請檢查

 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

正確放置-在調用initWithAdSize之后設置框架/邊界屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM