gpt4 book ai didi

ios - 带 Split View的 MMDrawerController

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:13:32 24 4
gpt4 key购买 nike

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

iPhone 的经典主/细节应用程序和 iPad 的 Split View。

我想使用 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 上,滑出菜单可以工作,详细 View 已加载,但我不知道如何定义 masterViewcontroller/navigationcontroller,所以它不起作用..

(抱歉,正如您所见,我是真正的 objective c 和 ios 概念人)

谢谢

最佳答案

@皮科洛

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

干杯

关于ios - 带 Split View的 MMDrawerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16953290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com