[英]How to place admob banner at bottom of screen in iOS retina and non retina
I've built a phonegap app and want to add an Admob banner to it. 我已经构建了一个phonegap应用程序,并希望为其添加Admob横幅。 I have the banner working at the bottom of the screen in iOS6 simulator but when I test it on a retina device the banner will be way off of the bottom like it's still trying to size the screen for a non retina display.
我在iOS6模拟器的屏幕底部有横幅,但是当我在视网膜设备上测试时,横幅将离开底部,就像它仍然试图调整屏幕的非视网膜显示一样。 Here is my current code in viewDidLoad:
这是我在viewDidLoad中的当前代码:
// Initialize the banner at the bottom of the screen.
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
// Use predefined GADAdSize constants to define the GADBannerView.
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = @"xxxxxxxxxxxx";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
你可以试试这个,
bannerView_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-GAD_SIZE_320x50.height, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
我通过将上面的代码从viewDidLoad
移动到webViewDidFinishLoad
来解决这个问题。
I used this code to count for NavigationBar and Status Bar: 我使用此代码来计算NavigationBar和状态栏:
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height -
self.navigationController.navigationBar.frame.size.height -
20 /* status bar */);
I haven't tested your code, so it may already be working, but using the non-origin init and resetting the origin afterwards seems to work: 我没有测试过你的代码,所以它可能已经在运行,但是使用非原始init并在之后重置原点似乎有效:
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
// Omitted: set up ad id, etc
CGRect frame = bannerView_.frame;
frame.origin.y = self.view.frame.size.height - frame.size.height;
bannerView_.frame = frame;
[self.view addSubview:bannerView_];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.