Issue with Split View Controller with UITabbarController in iOS7

独自空忆成欢 提交于 2019-12-24 11:26:55

问题


I am using UISplitViewController inside UITabbarController. Now the problem is that when I am trying to set translucent property of tabbar to NO then it shows an additional bar above the tab bar as shown in picture below.

Your help regarding the problem will be highly appreciated.

Thanks

- (void)setupTabbar {
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate = self;

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    tabBarController.tabBar.barTintColor = UIColorFromRGB(kTabbarTintColor);
    tabBarController.tabBar.tintColor = [UIColor whiteColor];
}

UINavigationController *homeNavController = [[UINavigationController alloc] initWithRootViewController:[root getViewController]];

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    homeNavController.navigationBar.barTintColor = UIColorFromRGB(kNavigationTintColor);
    homeNavController.toolbar.barTintColor = UIColorFromRGB(kNavigationTintColor);
}
else {
    homeNavController.navigationBar.tintColor = UIColorFromRGB(kNavigationTintColor);
    homeNavController.toolbar.tintColor = UIColorFromRGB(kNavigationTintColor);
}


if (IS_IPAD_LAYOUT_ENABLED) {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        _homeSplitViewController = [[UISplitViewController alloc] init];

        category *objCategory = [[category alloc] init];
        objCategory.category_id = kInstructionsCategoryId;

        articleview *instructionsView = (articleview *)[objCategory getViewController];
        UINavigationController *placeHolderNavController = [[UINavigationController alloc] initWithRootViewController:instructionsView];

        _homeSplitViewController.delegate = instructionsView;

        if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
            placeHolderNavController.navigationBar.barTintColor = UIColorFromRGB(kNavigationTintColor);
            placeHolderNavController.toolbar.barTintColor = UIColorFromRGB(kNavigationTintColor);
        }
        else {
            placeHolderNavController.navigationBar.tintColor = UIColorFromRGB(kNavigationTintColor);
            placeHolderNavController.toolbar.tintColor = UIColorFromRGB(kNavigationTintColor);
        }
        _homeSplitViewController.viewControllers = [NSArray arrayWithObjects:homeNavController, placeHolderNavController, nil];
        _homeSplitViewController.tabBarItem.title = @"Home";
        _homeSplitViewController.tabBarItem.image = [UIImage imageNamed:@"home_ico.png"];
    }
    else {
        homeNavController.tabBarItem.title = @"Home";
        homeNavController.tabBarItem.image = [UIImage imageNamed:@"home_ico.png"];
    }
}
else {
    homeNavController.tabBarItem.title = @"Home";
    homeNavController.tabBarItem.image = [UIImage imageNamed:@"home_ico.png"];
}


settingsviewcontroller *settingsViewController = [[settingsviewcontroller alloc] initWithNibName:@"settingsviewcontroller" bundle:nil];
UINavigationController *settingsNavController = [[UINavigationController alloc] initWithRootViewController:settingsViewController];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    settingsNavController.navigationBar.barTintColor = UIColorFromRGB(kNavigationTintColor);
}
else {
    settingsNavController.navigationBar.tintColor = UIColorFromRGB(kNavigationTintColor);
}

settingsNavController.tabBarItem.title = @"More";
settingsNavController.tabBarItem.image = [UIImage imageNamed:@"more_ico.png"];

SearchViewController *searchViewController = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];
UINavigationController *searchNavController = [[UINavigationController alloc] initWithRootViewController:searchViewController];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    searchNavController.navigationBar.barTintColor = UIColorFromRGB(kNavigationTintColor);
    searchNavController.toolbar.barTintColor = UIColorFromRGB(kNavigationTintColor);
}
else {
    searchNavController.navigationBar.tintColor = UIColorFromRGB(kNavigationTintColor);
    searchNavController.toolbar.tintColor = UIColorFromRGB(kNavigationTintColor);
}
searchNavController.tabBarItem.title = @"Search";
searchNavController.tabBarItem.image = [UIImage imageNamed:@"search_ico.png"];


category *objCategory = [[category alloc] init];
objCategory.category_id = kMenuBar2CatId;
objCategory.screen_type = @"list";
objCategory.short_label = kMenuBar2Title;

UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:[objCategory getViewController]];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    navController2.navigationBar.barTintColor = UIColorFromRGB(kNavigationTintColor);
    navController2.toolbar.barTintColor = UIColorFromRGB(kNavigationTintColor);
}
else {
    navController2.navigationBar.tintColor = UIColorFromRGB(kNavigationTintColor);
    navController2.toolbar.tintColor = UIColorFromRGB(kNavigationTintColor);
}
navController2.tabBarItem.title = kMenuBar2Title;
navController2.tabBarItem.image = [UIImage imageNamed:kMenuBarIcon2];


MyScheduleViewController *placeHolderVC = [[MyScheduleViewController alloc] initWithNibName:@"MyScheduleViewController" bundle:nil];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:placeHolderVC];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    navController3.navigationBar.barTintColor = UIColorFromRGB(kNavigationTintColor);
    navController3.toolbar.barTintColor = UIColorFromRGB(kNavigationTintColor);
}
else {
    navController3.navigationBar.tintColor = UIColorFromRGB(kNavigationTintColor);
    navController3.toolbar.tintColor = UIColorFromRGB(kNavigationTintColor);
}
navController3.tabBarItem.title = kMenuBar3Title;
navController3.tabBarItem.image = [UIImage imageNamed:kMenuBarIcon3];

[objCategory release];

if (IS_IPAD_LAYOUT_ENABLED) {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        tabBarController.viewControllers = [NSArray arrayWithObjects:_homeSplitViewController, searchNavController, navController2, navController3, settingsNavController, nil];
    }
    else {
        tabBarController.viewControllers = [NSArray arrayWithObjects:homeNavController, searchNavController, navController2, navController3, settingsNavController, nil];
    }
}
else {
    tabBarController.viewControllers = [NSArray arrayWithObjects:homeNavController, searchNavController, navController2, navController3, settingsNavController, nil];
}

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    self.window.tintColor = [UIColor whiteColor];
}

tabBarController.tabBar.translucent = NO;

self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = tabBarController;

}


回答1:


Just add this code on master's viewDidLoad:

self.splitViewController?.extendedLayoutIncludesOpaqueBars = true


来源:https://stackoverflow.com/questions/19935997/issue-with-split-view-controller-with-uitabbarcontroller-in-ios7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!