依赖于第三方的框架RESideMenu
1.AppDelegate.m中的实现
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. //在AppDelegate.h中声明属性,初始化tabBarController self.tabBar = [[UITabBarController alloc] init]; ViewController* vc1 = [[ViewController alloc] init]; vc1.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:0]; UINavigationController* nav1 = [[UINavigationController alloc] initWithRootViewController:vc1]; ViewController1* vc2 = [[ViewController1 alloc] init]; vc2.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1]; UINavigationController* nav2 = [[UINavigationController alloc] initWithRootViewController:vc2]; self.tabBar.viewControllers = @[nav1,nav2]; //初始化leftVC LeftController* left = [[LeftController alloc] init]; //初始化RESideMenu RESideMenu* menu = [[RESideMenu alloc] initWithContentViewController:self.tabBar leftMenuViewController:left rightMenuViewController:nil]; self.window.rootViewController= menu; return YES; }
2.left左侧菜单
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ AppDelegate* GHDelegate = (AppDelegate* )[UIApplication sharedApplication].delegate; ViewController1_1* vc = [[ViewController1_1 alloc] init]; //通过GHDelegate.tabBar.selectedIndex获得当前tabbaritem对应的nav,进行页面跳转 NSArray *arrControllers = GHDelegate.tabBar.viewControllers; if (GHDelegate.tabBar.selectedIndex==0) { UINavigationController* nav = (UINavigationController* )[arrControllers objectAtIndex:0]; //隐藏sideMenuViewController [self.sideMenuViewController hideMenuViewController]; //隐藏底部 vc.hidesBottomBarWhenPushed = YES; [nav pushViewController:vc animated:YES]; }else{ UINavigationController* nav = (UINavigationController* )[arrControllers objectAtIndex:1]; [self.sideMenuViewController hideMenuViewController]; vc.hidesBottomBarWhenPushed = YES; [nav pushViewController:vc animated:YES]; } }
3.RESideMenu常见的属性设置
- (void)awakeFromNib { self.parallaxEnabled = NO; //视图差效果 self.scaleContentView = YES; //中心视图缩放功能打开 self.contentViewScaleValue = 0.95; //侧滑出现时缩放比 self.scaleMenuView = NO; //侧滑出来的视图是否支持缩放 self.contentViewShadowEnabled = YES; //中心视图阴影效果,打开显得有层次感。 self.contentViewShadowRadius = 4.5; //中心视图阴影效果Radius self.panGestureEnabled = NO; //关闭拖动支持手势 //使用storyboard初始化中心视图和左视图。 self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentViewController"]; //tabbar controller self.leftMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"leftMenuViewController"]; }
时间: 2024-10-10 09:41:33