如何将横幅广告形式放置在屏幕底部?当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];
}
答案 0 :(得分:1)
你要覆盖你的变量,请检查
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
后设置frame / bounds属性