2

我有一个适用于 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 所以它不起作用..

(对不起,我是真正的 nood 与客观 c 和 ios 概念,如你所见)

谢谢你

4

3 回答 3

1

@picolo

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

干杯

于 2013-07-10T02:21:30.793 回答
1

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

链接在这里。--> MFSlideMenu

于 2013-12-31T11:17:31.450 回答
0

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

于 2013-06-07T06:44:14.867 回答