从头开始 ios 中的滑出式导航面板

Slide-Out Navigation Panel in ios from scratch

我想用 segue 为两侧(左侧和右侧)构建一个滑出式导航面板。在这种情况下我必须遵循的一些事情。左侧和右侧菜单 table 必须在 UIViewController 中(而不是在 UITableViewController 中)并且所有 viewController 都在 UINavigationController 中导航(嵌入式)。

我已经尝试了很多示例,但是所有示例都是 UITableViewController 完成的。因此,我无法根据我的设计自定义左侧或右侧菜单 table。

如果有人能给我一些参考或类似的教程,那将是非常感激的。

非常感谢。祝你有个美好的一天。

您可以使用 MMDrawcontroller 并通过 Navigationcontroller 传递 LeftView、RightView 和 Centerview。所有三个控制器都是 UIViewController。您还可以使用与 CenterView 相同的 NavigationController 添加左视图和右视图,以便您可以从左视图和右视图推送。

CenterVC *objCenter = [[CenterVC alloc] initWithNibName:@"CenterVC" bundle:nil];
LeftVC *objleftVC = [[LeftVC alloc] initWithNibName:@"LeftVC" bundle:nil];
RightVC *objrightVC = [[RightVC alloc] initWithNibName:@"RightVC" bundle:nil];

/*--- Init navigation for Center Controller ---*/
UINavigationController *_navC = [[UINavigationController alloc] initWithRootViewController:objCenter];
_navC.navigationBarHidden = YES;
_navC.navigationBar.translucent = NO;
MMDrawerController *drawerController = [[MMDrawerController alloc]
                                        initWithCenterViewController:_navC
                                        leftDrawerViewController:objleftVC
                                        rightDrawerViewController:objrightVC];
[drawerController setShowsShadow:NO];
[drawerController setRestorationIdentifier:@"MMDrawer"];
[drawerController setMaximumLeftDrawerWidth:[[UIScreen mainScreen] bounds].size.width-45.0];
[drawerController setMaximumRightDrawerWidth:[[UIScreen mainScreen] bounds].size.width-45.0];
[drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
[drawerController setShouldStretchDrawer:NO];

[drawerController
 setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
     MMDrawerControllerDrawerVisualStateBlock block;
     block = [[MMExampleDrawerVisualStateManager sharedManager]
              drawerVisualStateBlockForDrawerSide:drawerSide];
     if(block){
         block(drawerController, drawerSide, percentVisible);
     }
 }];


[self.navigationController pushViewController:drawerController animated:isAnimate];

使用 故事板 下载 (https://github.com/TomSwift/MMDrawerController-Storyboard)。添加 MMDrawerController+Storyboard 然后替换或检查上面演示中使用的 Storyboard,并按照演示在 AppDelegate 中添加代码。

因此您的演示项目将如下图所示

尝试SWRevealViewController。我认为这可能会满足您的所有要求。它有据可查,因此无需在此多说。