iOS将PKRevealController与故事板和自动布局集成
我试图将PKRevealController集成到我的现有项目中。iOS将PKRevealController与故事板和自动布局集成
https://github.com/pkluz/PKRevealController
如何设置我的左视图控制器,右视图控制器,和前视图控制器如果我用故事板?该自述说明要做...
PKRevealController *revealController = [PKRevealController revealControllerWithFrontViewController:frontVC leftViewController:leftVC options:options];
self.window.rootViewController = revealController;
我在哪里可以将这些代码行放在我现有的故事板项目中?或者有没有其他方法来设置它?
谢谢!
只需将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"];
}
}
我知道这是一个古老的线程,但我会出在这里反正:)
为了PKRevealController用故事板工作基本你就需要三个视图控制器。
BaseController(我把它叫做是),其中获得由PKRevealController怎么回事充当基地为主要内容控制器和导航控制器扩展。
MainController,它被设置为fronViewController。
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;
就是这样。
谢谢它的作品!但是,我们如何显示/隐藏菜单左侧或右侧,而不从前端vc刷卡? PLZ – 2017-07-15 23:02:29
我在这里回答了一个类似的问题:[在现有的Xcode Storyboard上使用pkRevealController](http://*.com/questions/14824959/using-pkrevealcontroller-on-existing-xcode-storyboard/14825615#14825615) – rdelmar 2013-02-14 23:42:57