gpt4 book ai didi

ios - 如何将 AdMob 横幅放置在底部?

转载 作者:行者123 更新时间:2023-11-29 03:34:51 28 4
gpt4 key购买 nike

如何将 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 后设置框架/边界属性

关于ios - 如何将 AdMob 横幅放置在底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19328119/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com