2013-06-06 115 views
1

我有一個iPhone和iPad的應用程序。MMDrawerController與分割視圖

一個經典的主/細節應用程序的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上,滑出菜單工作時,的DetailView被加載,但我不知道如何以定義masterViewcontroller/navigationcontroller所以它不工作。

(對不起,ima真正的目標c和ios的概念,你可以看到)

謝謝

回答

0

MMDrawerController不能使用SplitViewController。 (如github項目描述中所說的那樣)。

1

@picolo

不幸的是,蘋果公司強制執行UISplitViewController是一個窗口,這意味着你不能把它放在一個容器視圖控制器內的RootViewController的。您必須編寫自己的類似的分割視圖控制器實現,才能將其放入另一個容器視圖控制器中。

乾杯

1

MMDrawer不適用於SplitViewController。嘗試使用MFSlideMenu。它適用於幾乎所有類型的控制器。

這裏是鏈接。 - >MFSlideMenu

+0

您是否對MMDrawerController或MMDrawer只有Master視圖有任何想法?他們的Sample帶有SplitViewController –