我正在尝试在我的应用程序中使用MMDrawerController。我已经下载了源代码和依赖项。这是我添加到AppDelegate中的代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIViewController * leftDrawer = [[UIViewController alloc] init];
    UIViewController * center = [[UIViewController alloc] init];
    UIViewController * rightDrawer = [[UIViewController alloc] init];

    MMDrawerController * drawerController = [[MMDrawerController alloc]
                                             initWithCenterViewController:center
                                             leftDrawerViewController:leftDrawer
                                             rightDrawerViewController:rightDrawer];

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

    [navigationController setRestorationIdentifier:@"MMExampleCenterNavigationControllerRestorationKey"];

    [self.drawerController setRestorationIdentifier:@"MMDrawer"];
    [self.drawerController setMaximumRightDrawerWidth:200.0];
    [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];



    [self.drawerController
     setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
         UIViewController * sideDrawerViewController;
         if(drawerSide == MMDrawerSideLeft){
             sideDrawerViewController = drawerController.leftDrawerViewController;
         }
         else if(drawerSide == MMDrawerSideRight){
             sideDrawerViewController = drawerController.rightDrawerViewController;
         }
         [sideDrawerViewController.view setAlpha:percentVisible];
     }];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    [self.window setRootViewController:self.drawerController];

    return YES;
}

但是该应用程序运行到黑屏。我缺少什么?

最佳答案

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

[self.window setRootViewController:navigationController];

无需在下面的行中写:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

希望这将完美地工作。

关于ios - MMDrawerController实例化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21986287/

10-11 23:01