带有splitview的MMDrawerController

时间:2013-06-06 03:33:14

标签: ios

我有iphone和ipad的应用程序。

适用于iphone的经典主/详细应用和适用于ipad的splitview。

我想使用MMDrawerController Github

添加一个幻灯片菜单

我设法为iPhone添加它,但我知道如何为ipad添加它并保持splitview / NavigationController的行为。

原始代码:

 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    MyMasterViewController *masterViewController = [[MyMasterViewController alloc] initWithNibName:@"MyMasterViewController_iPhone" bundle:nil];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
    self.window.rootViewController = self.navigationController;
} else {
    MyMasterViewController *masterViewController = [[MyMasterViewController alloc] initWithNibName:@"MyMasterViewController_iPad" bundle:nil];
    UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];

    MyDetailViewController *detailViewController = [[MyDetailViewController alloc] initWithNibName:@"MyDetailViewController_iPad" bundle:nil];
    UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

    masterViewController.detailViewController = detailViewController;

    self.splitViewController = [[UISplitViewController alloc] init];
    self.splitViewController.delegate = detailViewController;
    self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];

    self.window.rootViewController = self.splitViewController;
}
[self.window makeKeyAndVisible];

尝试使用MMDrawerControler:

UIViewController * leftSideDrawerViewController = [[MMExampleLeftSideDrawerViewController alloc] init];

NSString *strViewMaster = @"MyMasterViewController_iPhone";
 UIViewController * centerViewController = [[MyMasterViewController alloc] initWithNibName:strViewMaster bundle:nil];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPhone) {
    strViewMaster = @"MyDetailViewController_iPad";
     centerViewController = [[MyDetailViewController alloc] initWithNibName:strViewMaster bundle:nil];
}

// unused
//UIViewController * rightSideDrawerViewController = [[MMExampleRightSideDrawerViewController alloc] init];

UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];

MMDrawerController * drawerController = [[MMDrawerController alloc]
                                         initWithCenterViewController:navigationController
                                         leftDrawerViewController:leftSideDrawerViewController];
[drawerController setMaximumRightDrawerWidth:200.0];

[drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModePanningNavigationBar];
[drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];

[drawerController
 setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
     MMDrawerControllerDrawerVisualStateBlock block;
     block = [[MMExampleDrawerVisualStateManager sharedManager]
              drawerVisualStateBlockForDrawerSide:drawerSide];
     if(block){
         block(drawerController, drawerSide, percentVisible);
     }
 }];

//centerViewController.mm_drawerController = drawerController;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:drawerController];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

所以,在ipad上,滑出菜单正在运行,详细视图已加载,但我不知道如何定义masterViewcontroller / navigationcontroller,因此它不起作用..

(对不起,我真的很喜欢你能看到的客观c和ios概念)

谢谢

3 个答案:

答案 0 :(得分:1)

@picolo

不幸的是,Apple强制将UISplitViewController作为窗口的rootViewController,这意味着您无法将其放在容器视图控制器中。您必须编写自己的类似拆分视图控制器实现,以便将其放在另一个容器视图控制器中。

干杯

答案 1 :(得分:1)

MMDrawer不适用于SplitViewController。尝试使用MFSlideMenu。它适用于几乎所有类型的控制器。

这是链接。 - > MFSlideMenu

答案 2 :(得分:0)

MMDrawerController不能与SplitViewController一起使用。 (如github项目描述中所述)。