使用SlideNavigationController实现侧滑菜
最近接到的项目当中使用到了侧滑菜单栏,由于本人所在公司属于外包,开发周期短暂,于是乎本人就Google到了一个强大并且使用很方便的框架:SlideNavigationController。
下面先放几张截图:
右滑.png
首页.png
左滑.png
使用的第一步当然是集成SlideNavigationController,我们可以使用cocoapods,也可以直接下载集成,关于cocoapods的使用网络上一大堆,我就不多做赘述了。
SlideNavigationController的使用相当简单,我们只需要在AppDelegate的
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法中添加如下代码:
[self.window setRootViewController:[[SlideNavigationController alloc] initWithRootViewController:[ViewController new]]];
ViewController2 *vc2 = [ViewController2 new]
ViewController1 *vc1 = [ViewController1 new];
[SlideNavigationController sharedInstance].leftMenu = vc1;
[SlideNavigationController sharedInstance].rightMenu = vc2;
就可以实现左滑和右滑菜单栏。SlideNavigationController有默认的barButtonItem图片,我们可以将SlideNavigationController.m
中的宏定义MENU_IMAGE
更改为自己需要用的图片。
上面的代码实现的是“左右开弓”式,如果我们只需要右滑或者左滑,那么只需要写出以下代码即可:
[SlideNavigationController sharedInstance].leftMenu = vc1;//左滑
或者
[SlideNavigationController sharedInstance].rightMenu = vc2;//右滑
SlideNavigationController还提供了以下可供定义的属性:
@property (nonatomic, assign) BOOL avoidSwitchingToSameClassViewController;
@property (nonatomic, assign) BOOL enableSwipeGesture//是否允许轻扫手势;
@property (nonatomic, assign) BOOL enableShadow//是否允许阴影;
@property (nonatomic, strong) UIViewController *rightMenu;
@property (nonatomic, strong) UIViewController *leftMenu;
@property (nonatomic, strong) UIBarButtonItem *leftBarButtonItem;
@property (nonatomic, strong) UIBarButtonItem *rightBarButtonItem;
@property (nonatomic, assign) CGFloat portraitSlideOffset//横向滑动偏移量;
@property (nonatomic, assign) CGFloat landscapeSlideOffse//纵向滑动偏移量t;
@property (nonatomic, assign) CGFloat panGestureSideOffset//手势作用范围;
@property (nonatomic, assign) CGFloat menuRevealAnimationDuration//动画时间;
@property (nonatomic, assign) UIViewAnimationOptions menuRevealAnimationOption//动画选项;
@property (nonatomic, strong) id <SlideNavigationContorllerAnimator> menuRevealAnimator;
这里是本人使用之前写的小demo,说不上研究,只是测试其功能,有兴趣的同学可以深入探索一下,然后大家交流交流。