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这个文件夹拖到工程中来,在工程启动入口那儿:

[cpp]  view plain copy
  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.   
  18. }  
当然,你先要定义一个 _revealSideViewController 并先实现它。

在跳转到我们的mainViewController后,我们需要先preLoad,预加载你的左、右viewContrller 这样用手势左右划动的时候就能跳到左右菜单了

[cpp]  view plain copy
  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];  
  17. }  

其它常用操作:

1 跳转到一个菜单

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

2 返回

[cpp]  view plain copy
  1. [self.revealSideViewController pushOldViewControllerOnDirection:PPRevealSideDirectionLeft animated:YES];  

3。在左/右边菜单跳转到一个新的页面

[cpp]  view plain copy
  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步中进行跳转后的新页面,还能划动到右边的菜单,有时候我们只想要一个左边菜单,要么上边的,可以用这个方法删除其它方向的:

[cpp]  view plain copy
  1. [self.revealSideViewController unloadViewControllerForSide:PPRevealSideDirectionRight];//删掉右边的viewController  

具体的菜单逻辑跟据自己项目中来吧,方法差不多就这些了,在PPRevealSideviewController的demo里写得比较清楚的,可以仔细研究一下。


我自己仿照“时光流”这个应用做了个左边菜单:





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值