我正在通过 AdMob 集成将我的付费 iPhone 应用程序转换为免费应用程序
为了简化集成,我将 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];
}