Question

My problem is when I present a UIViewController the presenting views are going black.

I have a UIViewController named mainViewController which is the root view of my windows. Inside I have a MMDrawerController (just added as a subview of mainViewController's view).

The MMDrawerController contains the rest of my views.

But when I'm presenting a new UIViewController from my mainViewController, the new VC displays well, but when it dismisses it left only black screen behind. To note the black screen appears when adding (I can see it directly). Not when dismissing.

For testing purpose I did this code :

UIViewController *vc = [UIViewController new];
vc.view.backgroundColor = [UIColor redColor];
[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:vc animated:NO completion:^{
    [vc dismissViewControllerAnimated:YES completion:nil];
}];

Which do the same black result as normal use. (normally it's a QLViewController...)

My mainViewController is set like it :

_mainViewController = [MyMainViewController new];
_window.rootViewController = _mainViewController;
[self.window addSubview:_mainViewController.view];

Souce code of MMDrawerController which is up to date in my project

Was it helpful?

Solution 2

In the end, the problem was that I applied inset constraints on my mainViewController.

Behind the scene I suppose that method presentViewController:animated:completion: use frames and not AutoLayout, which break the UIView of the UIViewController that are in the mainViewController.

Thanks to @simalone, I used the same way to find the origin of the problem (use MMDrawerController example project).

I you want to test yourself the problem, I uploaded the example project with the issue so you can understand it. There is a breakpoint on the line which is the origin of the bug. Then just double click on the view.

Thanks again to @simalone. Cheers !

OTHER TIPS

I have tested the code just in MMDrawerController example project, but I can't reproduce the problem, following is what I have tried:

MMAppDelegate.m

-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    //...

    UIViewController *testVc = [[UIViewController alloc] init];
    testVc.view.backgroundColor = [UIColor greenColor];
    [testVc.view addSubview:self.drawerController.view];

    [self.window setRootViewController:testVc];
    [self.window addSubview:testVc.view];

    return YES;
}

MMExampleSideDrawerViewController.m:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case MMDrawerSectionViewSelection:{
            UIViewController *vc = [UIViewController new];
            vc.view.backgroundColor  = [UIColor redColor];
            UIViewController *mainVC =  [[UIApplication sharedApplication] keyWindow].rootViewController;
            [mainVC presentViewController:vc animated:YES completion:^{
                [vc dismissViewControllerAnimated:YES completion:nil];
            }];

            return;
    //...
}

MMExampleCenterTableViewController.m:

-(void)doubleTap:(UITapGestureRecognizer*)gesture{
    UIViewController *vc = [UIViewController new];
    vc.view.backgroundColor  = [UIColor redColor];
    UIViewController *mainVC =  [[UIApplication sharedApplication] keyWindow].rootViewController;
    [mainVC presentViewController:vc animated:YES completion:^{
        [vc dismissViewControllerAnimated:YES completion:nil];
    }];

    return;

    [self.mm_drawerController bouncePreviewForDrawerSide:MMDrawerSideLeft completion:nil];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top