RESideMenu源码学习

RESideMenu

下载地址:https://github.com/romaonthego/RESideMenu

RESideMenu 有三个类,RECommonFunctions,RESideMenu,UIViewController+RESideMenu,核心RESideMenu类,因为RESideMenu 支持iOS 6+,但是一些动态效果是iOS 7+ 才有的API,在RECommonFunctions定义了一个宏,来区别系统是否是iOS 7+,目前来讲大部分App已经不支持iOS 6了,所以这个文件可以删去了,去掉RESideMenu删去这个判断,。

RESideMenu 继承UIViewController,里面有三个Controller 属性,

- (id)initWithContentViewController:(UIViewController *)contentViewController
leftMenuViewController:(UIViewController *)leftMenuViewController
rightMenuViewController:(UIViewController *)rightMenuViewController;
- (void)presentLeftMenuViewController;
- (void)presentRightMenuViewController;
- (void)hideMenuViewController;
- (void)setContentViewController:(UIViewController *)contentViewController animated:(BOOL)animated;

从初始化方法里很容易看出这个库是有三个ViewControoler组成,分别是

@property (strong, readwrite, nonatomic) UIViewController *contentViewController;
@property (strong, readwrite, nonatomic) UIViewController *leftMenuViewController;
@property (strong, readwrite, nonatomic) UIViewController *rightMenuViewController;

我们可以对着三个ViewController进行属性设置,

RESideMenuDelegate 方法用来回调三个控制器做交互的时候传递相应的事件

- (void)sideMenu:(RESideMenu *)sideMenu didRecognizePanGesture:(UIPanGestureRecognizer *)recognizer;
- (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController;
- (void)sideMenu:(RESideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController;
- (void)sideMenu:(RESideMenu *)sideMenu willHideMenuViewController:(UIViewController *)menuViewController;
- (void)sideMenu:(RESideMenu *)sideMenu didHideMenuViewController:(UIViewController *)menuViewController;

都是可选操作,需要监听一些动作的时候,在相应的代理方法写操作即可。