SWRevealViewController 是一个比较好的实现Sliding功能的第三方类。
今天跟大家分享一下如何使用SWRevealViewController实现左右菜单滑动功能。
首先,在工程中创建三个类,依次为 RootViewController、LeftViewController、RightViewController。
在工程中添加SWRevealViewController类以及所需要的图片。
在AppDelegate中添加如下代码:
RootViewController* rootViewController = [[RootViewController alloc] init];
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
LeftViewController* leftViewController = [[LeftViewController alloc] init];
RightViewController* rightViewController = [[RightViewController alloc] init];
SWRevealViewController* revealViewController = [[SWRevealViewController alloc] initWithRearViewController:leftViewController frontViewController:navigationController];
[revealViewController setRightViewController:rightViewController];
self.window.rootViewController = revealViewController;
SWRevealViewController *revealController = self.revealViewController;
UIButton* leftButton = [self navigationButtonWithTitle:nil image:[UIImage imageNamed:@"ico_home_menu"] target:revealController action:@selector(revealToggle:)];
UIBarButtonItem* leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
self.navigationItem.leftBarButtonItem = leftBarButton;
UIButton* rightButton = [self navigationButtonWithTitle:nil image:[UIImage imageNamed:@"ico_home_menu"] target:revealController action:@selector(rightRevealToggle:)];
UIBarButtonItem* rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
self.navigationItem.rightBarButtonItem = rightBarButton;