【问题标题】:iOS 7 iAds with TabBar Controller and Navigation Controller带有 TabBar 控制器和导航控制器的 iOS 7 iAd
【发布时间】:2014-06-19 01:41:57
【问题描述】:

我有一个UITabBarControllerUINavigationController 在我想在其中使用 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


    【解决方案1】:

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

    在 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;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-21
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多