您的位置:首页 > 移动开发 > IOS开发

iOS左右菜单PPRevealSideviewController

2014-02-10 18:52 246 查看
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 plaincopy

- (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;

}

当然,你先要定义一个 _revealSideViewController 并先实现它。
在跳转到我们的mainViewController后,我们需要先preLoad,预加载你的左、右viewContrller 这样用手势左右划动的时候就能跳到左右菜单了

[cpp]
view plaincopy

- (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 跳转到一个菜单

[cpp]
view plaincopy

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

2 返回

[cpp]
view plaincopy

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

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

[cpp]
view plaincopy

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

[cpp]
view plaincopy

[self.revealSideViewController unloadViewControllerForSide:PPRevealSideDirectionRight];//删掉右边的viewController

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

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


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: