带有TabBar控制器和导航控制器的iOS 7 iAd

时间:2014-06-17 22:48:53

标签: ios uinavigationcontroller uitabbarcontroller iad

我在应用程序中有一个UITabBarControllerUINavigationController,其中包含我想要使用iAd的故事板。我正在使用BannerViewController.h& Apple在iAdSuite演示中提供的.m文件。在没有导航控制器的选项卡式视图中,AdBannerView加载正常。当我使用导航控制器切换到标签时,标签栏上方屏幕底部有一个黑条(窗口)。当AdBannerView加载时,它会在黑条上移动,应用程序看起来很好。当它无法加载时,黑条会回来。当AdBannerView未显示时,此黑色条也会显示在推送到导航控制器堆栈的每个视图上。

如何删除此黑条?

这是AdBannerView尚未加载的视图。通常它有蓝色背景一直到标签栏。当使用带有标签栏和标签栏的BannerViewController时,黑条开始出现。导航控制器
AdBannerView did not load yet 这是AdBannerView加载的时候 AdBannerView did load

以下是一些代码:

在TabBarViewController.m中:

//Implement BannerViewControllers on all the views in the Tab Bar
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIStoryboard *storyboard = nil;
if (screenBounds.size.height == 568) {
    storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone4" bundle: nil];
} else {
    storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone35" bundle: nil];
}
UINavigationController *firstViewController = [storyboard instantiateViewControllerWithIdentifier:@"NavView"];
AboutViewController *secondViewController = [storyboard instantiateViewControllerWithIdentifier:@"AboutView"];
ContactViewController *thirdViewController = [storyboard instantiateViewControllerWithIdentifier:@"ContactView"];

NSMutableArray *mutArray = [[NSMutableArray alloc] init];
[mutArray addObjectsFromArray:self.viewControllers];
[mutArray replaceObjectAtIndex:0 withObject:[[BannerViewController alloc] initWithContentViewController:firstViewController]];
[mutArray replaceObjectAtIndex:1 withObject:[[BannerViewController alloc] initWithContentViewController:secondViewController]];
[mutArray replaceObjectAtIndex:2 withObject:[[BannerViewController alloc] initWithContentViewController:thirdViewController]];
NSArray *array = [NSArray arrayWithArray:mutArray];
[self setViewControllers:array];

取自iAdSuite中的TabbedBanner:

在BannerViewController.m中:

- (void)loadView
{
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Setup containment of the _contentController.
[self addChildViewController:_contentController];
[contentView addSubview:_contentController.view];
[_contentController didMoveToParentViewController:self];

self.view = contentView;

}

- (void)viewDidLayoutSubviews
{
CGRect contentFrame = self.view.bounds, bannerFrame = CGRectZero;
ADBannerView *bannerView = [BannerViewManager sharedInstance].bannerView;
NSLog(@"Content frame before layout = %@",NSStringFromCGRect(contentFrame));

bannerFrame.size = [bannerView sizeThatFits:contentFrame.size];

if (bannerView.bannerLoaded) {
    contentFrame.size.height -= bannerFrame.size.height;
    bannerFrame.origin.y = contentFrame.size.height;
} else {
    bannerFrame.origin.y = contentFrame.size.height;
}
NSLog(@"Content frame after layout = %@",NSStringFromCGRect(contentFrame));

//_contentController.view.frame = contentFrame;
//I commented this out because AdBannerView will move the black bar up instead of covering it. 

// We only want to modify the banner view itself if this view controller is actually visible to the user.
// This prevents us from modifying it while it is being displayed elsewhere.
if (self.isViewLoaded && (self.view.window != nil)) {
    [self.view addSubview:bannerView];
    bannerView.frame = bannerFrame;

}
}

1 个答案:

答案 0 :(得分:0)

实现黑条是显示的窗口,我将contentController的框架扩展了50以覆盖它。我仍然不知道为什么它只发生在Tab + Nav Controller组合中,但这里是修复它的代码

在BannerViewController.m中:

- (void)loadView
{
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Setup containment of the _contentController.
[self addChildViewController:_contentController];
[contentView addSubview:_contentController.view];
[_contentController didMoveToParentViewController:self];
_contentController.view.frame = CGRectMake(0, 0, 320, 618); //This is what saved me
self.view = contentView;

}