2013-02-14 78 views
8

我试图将PKRevealController集成到我的现有项目中。iOS将PKRevealController与故事板和自动布局集成

https://github.com/pkluz/PKRevealController

如何设置我的左视图控制器,右视图控制器,和前视图控制器如果我用故事板?该自述说明要做...

PKRevealController *revealController = [PKRevealController revealControllerWithFrontViewController:frontVC leftViewController:leftVC options:options]; 

self.window.rootViewController = revealController; 

我在哪里可以将这些代码行放在我现有的故事板项目中?或者有没有其他方法来设置它?

谢谢!

+3

我在这里回答了一个类似的问题:[在现有的Xcode Storyboard上使用pkRevealController](http://stackoverflow.com/questions/14824959/using-pkrevealcontroller-on-existing-xcode-storyboard/14825615#14825615) – rdelmar 2013-02-14 23:42:57

回答

2

只需将segue目标控制器的类型设置为PKRevealController并为前视图,左视图控制器和右视图控制器设置故事板ID即可。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 

    if ([segue.identifier isEqualToString:@"ToMain"]) { 

    PKRevealController* prc = segue.destinationViewController; 

    prc.frontViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"FrontViewController"]; 
    prc.leftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"]; 
    prc.rightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"RightViewController"]; 

    } 
} 
+0

I don没办法。这是否意味着我应该使我的故事板的'PKRevealController'入口点?我不能只从标签栏按钮点击处理程序调用PKRevealController? – expert 2013-09-10 07:12:35

+0

在我的情况下,'leftViewController'也是只读属性。 – expert 2013-09-10 08:00:05

+1

值得注意的是,这不起作用。您可以在IB中将视图控制器设置为拥有'PKRevealController'类,但是当发生轮播时,屏幕是空白的,只是半透明的灰色。 – barndog 2014-07-26 03:08:30

2

我知道这是一个古老的线程,但我会出在这里反正:)

为了PKRevealController用故事板工作基本你就需要三个视图控制器。

  1. BaseController(我把它叫做是),其中获得由PKRevealController怎么回事充当基地为主要内容控制器和导航控制器扩展。

  2. MainController,它被设置为fronViewController。

  3. NaviController,我们基本上使用它作为leftViewController,aka导航菜单。

仅供参考:您可以设计和编码从主板上的MainController和NaviController。

所以这是我们如何做到的;首先,我们需要像这样用PKRevealController扩展BaseController;

@interface MainController : PKRevealController 

其次,仍然在BaseController中,将这些行添加到viewDidLoad方法中;

//init the fonrViewController 
UIViewController *homeController = [self.storyboard instantiateViewControllerWithIdentifier:@"homeScreen"]; 
//init the leftViewController 
UIViewController *naviContrlller = [self.storyboard instantiateViewControllerWithIdentifier:@"quickNaviScreen"]; 

[self setFrontViewController:homeController]; 
[self setLeftViewController:naviContrlller]; 

然后设置PKRevealController委托为;

self.delegate = self; 

就是这样。

+0

谢谢它的作品!但是,我们如何显示/隐藏菜单左侧或右侧,而不从前端vc刷卡? PLZ – 2017-07-15 23:02:29