此前iPhone 5,我可以将AdMob的横幅屏幕(只是上面的标签栏)的底部。但由于iPhone 5的屏幕尺寸,一切都是现在不安。我甚至试图通过自动布局做到这一点(没有工作)。我怎样才能做到这两种屏幕尺寸?
Prior to iPhone 5, i could place the admob banner at the bottom of the screen (just above the tab bar). But due to iPhone 5 screen size, everything is now disturbed. I even tried to do it through Autolayout (it didn't work). How can i do that for both screen sizes?
下面是我的code -
Here's my code -
-(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.
}
任何帮助将是AP preciated!
Any help would be appreciated!
如果你使用的是iOS 6,你应该只使用自动版式。你可以把这个code到您的广告位置code后添加的旗帜到视图层次:
If you're using iOS 6 you should just use AutoLayout. You can put this code into your ad placement code after you add the banner into the view hierarchy:
[self.view addSubview:self.adBanner];
// Constraint keeps ad at the bottom of the screen at all times.
[self.view addConstraint:
[NSLayoutConstraint constraintWithItem:self.adBanner
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0]];
// Constraint keeps ad in the center of the screen at all times.
[self.view addConstraint:
[NSLayoutConstraint constraintWithItem:self.adBanner
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0]];
self.adBanner.translatesAutoresizingMaskIntoConstraints = NO;