Ios左右菜單PPRevealSideviewController使用的一些心得

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這個文件夾拖到工程中來,在工程啓動入口那兒:

  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  2. {  
  3.     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];  
  4.       
  5.     MainViewController *main = [[MainViewController alloc] init];//你自己的中間controller  
  6.     UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:main];  
  7.     _revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav];  
  8.     _revealSideViewController.delegate = self;  
  9.     self.window.rootViewController = _revealSideViewController;  
  10.       
  11.     PP_RELEASE(main);  
  12.     PP_RELEASE(nav);  
  13.       
  14.     self.window.backgroundColor = [UIColor whiteColor];  
  15.     [self.window makeKeyAndVisible];  
  16.     return YES;  
  17.   

當然,你先要定義一個 _revealSideViewController 並先實現它。

在跳轉到我們的mainViewController後,我們需要先preLoad,預加載你的左、右viewContrller 這樣用手勢左右划動的時候就能跳到左右菜單了

  1. - (void) preloadView {  
  2.     LeftViewController *left = [[[LeftViewController alloc] init] autorelease];  
  3.     [self.revealSideViewController preloadViewController:left 

  4.                                                  forSide:PPRevealSideDirectionLeft  
  5.                                               withOffset:_offset];  
  6.       
  7.     RightViewController *right = [[[RightViewController alloc] init] autorelease];  
  8.     [self.revealSideViewController preloadViewController:right  
  9.                                                  forSide:PPRevealSideDirectionRight  
  10.                                               withOffset:_offset];  
  11. }  
  12.   
  13. - (void) viewDidAppear:(BOOL)animated {  
  14.     [super viewDidAppear:animated];  
  15.     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(preloadView) object:nil];  
  16.     [self performSelector:@selector(preloadView) withObject:nil afterDelay:0.3];  

其它常用操作:

1 跳轉到一個菜單

  1. LeftViewController *left = [[LeftViewController alloc] init];  
  2. [self.revealSideViewController pushViewController:left onDirection:PPRevealSideDirectionLeft withOffset:_offset animated:_animated];  
  3. PP_RELEASE(left);  

2 返回

  1. [self.revealSideViewController pushOldViewControllerOnDirection:PPRevealSideDirectionLeft animated:YES];  

3。在左/右邊菜單跳轉到一個新的頁面
  1. SecondViewController *c = [[SecondViewController alloc] init];  
  2. UINavigationController *n = [[UINavigationController alloc] initWithRootViewController:c];  
  3. [self.revealSideViewController popViewControllerWithNewCenterController:n animated:YES];  
  4. PP_RELEASE(c);  
  5. PP_RELEASE(n);  

 4  用第3步中進行跳轉後的新頁面,還能划動到右邊的菜單,有時候我們只想要一個左邊菜單,要麼上邊的,可以用這個方法刪除其它方向的:

  1. [self.revealSideViewController unloadViewControllerForSide:PPRevealSideDirectionRight];//刪掉右邊的viewController  

具體的菜單邏輯跟據自己項目中來吧,方法差不多就這些了,在PPRevealSideviewController的demo裏寫得比較清楚的,可以仔細研究一下。





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章