2
我爲我付出的iPhone應用程序轉換成一個自由,向AdMob整合中的AppDelegate和自動調整大小視圖使用AdMob的
爲了簡化集成,我加入AdMobView到AppDelegate中。
這一切都很好,因爲它在屏幕底部顯示廣告。但不幸的是,它覆蓋了以前在底部顯示的內容,而後續視圖被推送到navigationController的情況也是如此。有沒有一種方法可以讓Interface Builder將內容「擠壓」在一起,以使廣告視圖位於底部,同時讓所有其他按鈕和視圖可見?
這裏是AdMob的整合AppDelegate的代碼的一個子集:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
MyViewController *viewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController release];
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
// Request an ad
adMobAd = [AdMobView requestAdWithDelegate:self]; // start a new ad request
[adMobAd retain]; // this will be released when it loads (or fails to load)
return YES;
}
- (UIViewController *)currentViewControllerForAd:(AdMobView *)adView {
return navigationController;
}
// Sent when an ad request loaded an ad; this is a good opportunity to attach
// the ad view to the hierachy.
- (void)didReceiveAd:(AdMobView *)adView {
// get the view frame
CGRect frame = self.window.frame;
// put the ad at the bottom of the screen
adMobAd.frame = CGRectMake(0, frame.size.height - 48, frame.size.width, 48);
[navigationController.view addSubview:adMobAd];
}
這是一個古老的答案,但我只想補充一點,有時AdMob將不會顯示廣告,但鑑於依然存在,所以雖然你沒有看到它,但它仍然屏蔽了屏幕的這一部分。 – 2012-01-19 18:56:31