在iPhone 5之前,我可以将ADMOB横幅放在屏幕底部(就在标签栏上方)。但是由于iPhone 5屏幕尺寸,现在一切都受到了干扰。我什至试图通过自动层(它不起作用)来完成。我该如何对两个屏幕尺寸进行操作?
这是我的代码 -
-(void) viewDidLoad {
[super viewDidLoad];
adMob = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,
367.0 -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
adMob.translatesAutoresizingMaskIntoConstraints=NO;
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
adMob.adUnitID = @"XXXXXXXX";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
adMob.rootViewController = self;
GADRequest *request = [GADRequest request];
request.testing=YES;
[self.view addSubview:adMob];
// Initiate a generic request to load it with an ad.
[adMob loadRequest:[GADRequest request]];
[adMob release];
// Create a view of the standard size at the bottom of the screen.
// Available AdSize constants are explained in GADAdSize.h.
}
任何帮助将不胜感激!
如果您使用的是iOS 6,则应使用autoLayout。将横幅添加到视图层次结构之后,您可以将此代码放入广告位置代码中:
self.googleAdBannerView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.googleAdBannerView];
// Constraint keeps ad at the bottom of the screen at all times.
[self.googleAdBannerView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;
// Constraint keeps ad in the center of the screen at all times.
[self.googleAdBannerView.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor].active = YES;
根据他们使用的屏幕更改y
位置。
您必须使用视图的自动布局属性,没有其他方法可以解决,因为在视图的任何设备高度中保持相同,现在为499.0。