【发布时间】:2014-06-19 01:41:57
【问题描述】:
我有一个UITabBarController 和UINavigationController 在我想在其中使用 iAd 的故事板的应用程序中。我在 iAdSuite 演示中使用 Apple 提供的 BannerViewController.h 和 .m 文件。在没有导航控制器的选项卡式视图中,AdBannerView 加载正常。当我使用导航控制器切换到选项卡时,在选项卡栏上方的屏幕底部有一个黑条(窗口)。当 AdBannerView 加载时,它会移到黑条上,应用程序看起来很好。加载失败时,黑条又回来了。当AdBannerView 未显示时,此黑条也会出现在推送到导航控制器堆栈的每个视图上。
如何去除这个黑条?
这是 AdBannerView 尚未加载时的视图。通常,它一直到标签栏都有蓝色背景。使用带有标签栏和导航控制器的 BannerViewController 时,黑条开始出现
这是 AdBannerView 加载的时间
这里有一些代码:
在 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;
}
}
【问题讨论】:
标签: ios uinavigationcontroller uitabbarcontroller iad