PPRevealSideviewController是一個左右移動佈局,ios左右菜單的一個東西,功能非常強大,使用起來也很方便。
下載PPRevealSideviewController,下載地址
下載下來後有個叫PPRevealSideViewController的項目,打開就是整個demo,demo寫得非常強大,這兒主要解釋下各個開關的作用。
先看一下圖:
Animated:是否有動畫
Shadow:中間界面陰影
Resize:左邊的tableView菜單是否有一個下拉條
Bounce:是否有一點點彈跳,當你沒有初始化left/right/top/down的controller,你向left/right/top/down方向拉的時候,雖然不能跳轉界面,但是有個彈跳的一個小效果
Close Full:是否能從左直接拉到右邊
Offset:偏移量
Opened:可以看到opened的開關上面有個NavBar和Content,這兒的開關是指,是否可以用手勢Opend這個頁面,在哪兒的手勢呢?一個是NavBar上的手勢,另一個當然是content的了。
Closed:同Opened
Tap closed:是否可以點擊進行關閉頁面,上面的opened和Closed指的是手勢,這兒指的是點擊。
Keep offset:這個我暫時也不清楚 ^_^
其它帶字的比較好理解了,可以自己試一下。
說下大概用法吧:
下載下來後,把PPRevealSideviewController這個文件夾拖到工程中來,在工程啓動入口那兒:
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
- MainViewController *main = [[MainViewController alloc] init];//你自己的中間controller
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:main];
- _revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav];
- _revealSideViewController.delegate = self;
- self.window.rootViewController = _revealSideViewController;
- PP_RELEASE(main);
- PP_RELEASE(nav);
- self.window.backgroundColor = [UIColor whiteColor];
- [self.window makeKeyAndVisible];
- return YES;
- }
在跳轉到我們的mainViewController後,我們需要先preLoad,預加載你的左、右viewContrller 這樣用手勢左右划動的時候就能跳到左右菜單了
- - (void) preloadView {
- LeftViewController *left = [[[LeftViewController alloc] init] autorelease];
- [self.revealSideViewController preloadViewController:left
- forSide:PPRevealSideDirectionLeft
- withOffset:_offset];
- RightViewController *right = [[[RightViewController alloc] init] autorelease];
- [self.revealSideViewController preloadViewController:right
- forSide:PPRevealSideDirectionRight
- withOffset:_offset];
- }
- - (void) viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(preloadView) object:nil];
- [self performSelector:@selector(preloadView) withObject:nil afterDelay:0.3];
- }
其它常用操作:
1 跳轉到一個菜單
- LeftViewController *left = [[LeftViewController alloc] init];
- [self.revealSideViewController pushViewController:left onDirection:PPRevealSideDirectionLeft withOffset:_offset animated:_animated];
- PP_RELEASE(left);
2 返回
- [self.revealSideViewController pushOldViewControllerOnDirection:PPRevealSideDirectionLeft animated:YES];
3。在左/右邊菜單跳轉到一個新的頁面
- SecondViewController *c = [[SecondViewController alloc] init];
- UINavigationController *n = [[UINavigationController alloc] initWithRootViewController:c];
- [self.revealSideViewController popViewControllerWithNewCenterController:n animated:YES];
- PP_RELEASE(c);
- PP_RELEASE(n);
4 用第3步中進行跳轉後的新頁面,還能划動到右邊的菜單,有時候我們只想要一個左邊菜單,要麼上邊的,可以用這個方法刪除其它方向的:
- [self.revealSideViewController unloadViewControllerForSide:PPRevealSideDirectionRight];//刪掉右邊的viewController
具體的菜單邏輯跟據自己項目中來吧,方法差不多就這些了,在PPRevealSideviewController的demo裏寫得比較清楚的,可以仔細研究一下。