2

我正在通过 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];
}
4

1 回答 1

0

您可以调整 navigationController.view.frame 的大小,以便 adMobAd 不会阻止内容。

基本上将其添加到您的 didReceiveAd 调用的末尾:

CGRect navFrame = navigationController.view.frame;
navFrame.height -= 48;
navigationController.view.frame = navFrame;
于 2010-11-06T02:17:22.643 回答