我已经构建了一个phonegap应用,并希望为其添加Admob横幅。我在iOS6模拟器的屏幕底部有横幅,但是当我在视网膜设备上测试时,横幅将离开底部,就像它仍然试图调整屏幕的非视网膜显示一样。这是我在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]];
答案 0 :(得分:6)
你可以试试这个,
bannerView_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-GAD_SIZE_320x50.height, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
答案 1 :(得分:4)
我通过将上述代码从viewDidLoad
移到webViewDidFinishLoad
来解决了这个问题。
答案 2 :(得分:1)
我使用此代码计算导航栏和状态栏:
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height -
self.navigationController.navigationBar.frame.size.height -
20 /* status bar */);
答案 3 :(得分:0)
我还没有测试过您的代码,所以它可能已经有效了,但是使用非原始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_];