簡體   English   中英

如何在iOS視網膜和非視網膜的屏幕底部放置admob橫幅

[英]How to place admob banner at bottom of screen in iOS retina and non retina

我已經構建了一個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]];

你可以試試這個,

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來解決這個問題。

我使用此代碼來計算NavigationBar和狀態欄:

CGPoint origin = CGPointMake(0.0,
                             self.view.frame.size.height -
                             CGSizeFromGADAdSize(kGADAdSizeBanner).height -
                             self.navigationController.navigationBar.frame.size.height -
                             20 /* status bar */);

我沒有測試過你的代碼,所以它可能已經在運行,但是使用非原始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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM