一个做好的滑动菜单。
lib/NVSlideMenuController/NVSlideMenuController.{h|m}
添加到您的项目中QuartzCore.framework
创建滑动菜单
UIViewController *menuViewController = ... ; // Your menu view controller
UIViewController *contentViewController = ... ; // The initial content view controller (home page ?)
NVSlideMenuController *slideMenuController = [[NVSlideMenuController alloc] initWithMenuViewController:menuViewController andContentViewController:contentViewController];
self.window.rootViewController = slideMenuController; // Assuming you are in app delegate did finish launching
从菜单中更改并显示新内容
// Inside your menuViewController
UIViewController *newContentViewController = ... ; // Create & configure your new content view controller (as usual)
[self.slideMenuController closeMenuBehindContentViewController:newContentViewController animated:YES completion:nil];
NVSlideMenuController 回调
此库通过 UIViewController 类别提供了 4 个方法。您可以覆盖它们来管理内容视图控制器中的滑动进/出。详情请看提供的演示应用程序。
@interface UIViewController (NVSlideMenuControllerCallbacks)
- (void)viewWillSlideIn:(BOOL)animated inSlideMenuController:(NVSlideMenuController *)slideMenuController;
- (void)viewDidSlideIn:(BOOL)animated inSlideMenuController:(NVSlideMenuController *)slideMenuController;
- (void)viewWillSlideOut:(BOOL)animated inSlideMenuController:(NVSlideMenuController *)slideMenuController;
- (void)viewDidSlideOut:(BOOL)animated inSlideMenuController:(NVSlideMenuController *)slideMenuController;
@end
更改滑动方向
您可以设置 slideDirection
属性为 NVSlideMenuControllerSlideFromLeftToRight
或 NVSlideMenuControllerSlideFromRightToLeft
来指定滑动方向。如果需要,视图将相应更新(查看演示应用程序获得感受)。您还可以进行动画更改。
// Inside your view controller (menu or content)
[self.slideMenuController setSlideDirection:NVSlideMenuControllerSlideFromRightToLeft animated:YES];
// or more simply...
self.slideMenuController.slideDirection = NVSlideMenuControllerSlideFromRightToLeft; // this one will not animate
启用/禁用拖动手势
您可能需要禁用拖动手势,例如当内容视图控制器有一个具有重新排序控制的表格视图时(参见问题 #2)。
// For example when your view controller enter in editing mode
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
if (editing)
self.slideMenuController.panGestureEnabled = NO;
}
更多内容请查看演示应用程序 ;-]
Nicolas VERINAUD (@nverinaud)
在 MIT 许可证下发布。更多请见 LICENSE.md
。