关于ios:MMDrawerController with splitview

MMDrawerController with splitview

我有一个适用于 iphone 和 ipad 的应用程序。

一个经典的 iphone 主/详细应用程序和 ipad 的 splitview。

我想使用 MMDrawerController Github 添加一个滑出菜单

我设法为 iphone 添加它,但我不明白如何为 ipad 添加它并保持 splitview / NavigationController 行为。

原始代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 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 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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概念)

谢谢你


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

这是链接。 –> MFSlideMenu


@picolo

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

干杯


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


原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/268714.html

(0)
上一篇 2022年6月20日
下一篇 2022年6月20日

相关推荐

发表回复

登录后才能评论