我想使用uitabbarcontroller实现侧边栏(抽屉)。我已经使用lib JASidePanel实现了uiviewcontroller。但是我没有找到任何用uitabarcontroller实现的方法。
感谢您的帮助
答案 0 :(得分:2)
使用MFSideMenu,https://github.com/mikefrederick/MFSideMenu
它有详细记录并支持UITabBarController。
答案 1 :(得分:0)
我将MMDrawerController与TabBar一起用作边栏。
这是我的MMDrawer和tabBar初始化代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[MMExampleDrawerVisualStateManager sharedManager] setRightDrawerAnimationType:MMDrawerAnimationTypeParallax];
self.tabbarController = [[UITabBarController alloc] init];
self.tabbarController.delegate = self;
JSIntroViewController *obj_loginViewController = [[JSIntroViewController alloc] initWithNibName:@"JSIntroViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:obj_loginViewController];
self.navigationController.navigationBarHidden = YES;
[self initializeTabBarControllerwithAnimation:FALSE];
UIViewController *rightViewController = [[JSMenuViewController alloc] init];
self.drawerController = [[MMDrawerController alloc]
initWithCenterViewController:self.navigationController
leftDrawerViewController:nil
rightDrawerViewController:rightViewController];
[self.drawerController setShowsShadow:NO];
[self.drawerController setRestorationIdentifier:@"MMDrawer"];
[self.drawerController setMaximumRightDrawerWidth:[UIScreen mainScreen].bounds.size.width-65];
[self.drawerController setGestureShouldRecognizeTouchBlock:^BOOL(MMDrawerController *drawerController, UIGestureRecognizer *gesture, UITouch *touch) {
if([gesture isKindOfClass:[UITapGestureRecognizer class]])
return YES;
return NO;
}];
[self.drawerController
setDrawerVisualStateBlock:^(MMDrawerController *drawerControllerr, MMDrawerSide drawerSide, CGFloat percentVisible) {
MMDrawerControllerDrawerVisualStateBlock block;
block = [[MMExampleDrawerVisualStateManager sharedManager]
drawerVisualStateBlockForDrawerSide:drawerSide];
if(block)
block(drawerControllerr, drawerSide, percentVisible);
}];
}
这是tabBar初始化的方法。
- (void)initializeTabBarControllerwithAnimation:(BOOL)animation
{
//First tab as Browse Job
JSBrowseViewController *obj_browseViewController = [[JSBrowseViewController alloc] initWithNibName:@"JSBrowseViewController" bundle:nil];
//BrowseViewController *obj_browseViewController = [[BrowseViewController alloc] initWithNibName:@"BrowseViewController" bundle:nil];
UINavigationController *navi1 = [[UINavigationController alloc] initWithRootViewController:obj_browseViewController];
navi1.navigationBar.translucent = NO;
//Second tab as Liked Job
LikedViewController *obj_likedViewController = [[LikedViewController alloc] initWithNibName:@"LikedViewController" bundle:nil];
UINavigationController *navi2 = [[UINavigationController alloc] initWithRootViewController:obj_likedViewController];
navi2.navigationBar.translucent = NO;
[self.tabbarController setViewControllers:[NSArray arrayWithObjects:navi1, navi2, nil]];
[self.tabbarController setSelectedIndex:0];
UITabBar *tabBar = self.tabbarController.tabBar;
tabBar.translucent = NO;
[tabBar setBackgroundColor:[UIColor whiteColor]];
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
[tabBarItem1 setTitle:@"BROWSE"];
[tabBarItem2 setTitle:@"LIKED"];
[tabBarItem1 setImage:[[UIImage imageNamed:@"browser-icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"browser-sel-icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem2 setImage:[[UIImage imageNamed:@"like-icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem2 setSelectedImage:[[UIImage imageNamed:@"like-sel-icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
selectedTabIndex = 0;
self.navigationController.navigationBarHidden = TRUE;
[self.navigationController pushViewController:self.tabbarController animated:animation];
}
答案 2 :(得分:0)
您可以使用SWRevealViewController - 它是紧凑的(只有2个文件)并且易于使用。