romaonthego / RESideMenu

iOS 7/8 style side menu with parallax effect.
MIT License
7.09k stars 1.35k forks source link

RESide menu presents and then disappears, all Viewcontrollers are taken off the stack #299

Open joycesin opened 7 years ago

joycesin commented 7 years ago

In AppDelegate, I have initialised the content view controller as the root navigation controller and rightMenuViewController as the desired UIViewController with my UITableViewController in my storyboard.

self.rootNavVC = (UINavigationController *)self.window.rootViewController;
rightMenuVC *rightMenuViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"rightMenuVC"];

// Create side menu controller
self.menuVC = [[RESideMenu alloc] initWithContentViewController:self.rootNavVC leftMenuViewController:nil rightMenuViewController:rightMenuVC];

// Make it a root controller
self.window.rootViewController = self.menuVC;

Now in the particular viewcontroller I want to display the RESide menu in, I am trying to present the RightMenuViewController. I wrote the code in viewDidLoad and want the menu to be presented immediately.

[super viewDidLoad];
[APP_DELEGATE.menuVC setContentViewController: self animated:NO];
[self performSelectorOnMainThread:@selector(presentRightMenuViewController:) withObject:nil waitUntilDone:YES];

However, I get a blank screen and when I inspect the view hierarchy, all my previous view controllers are gone, it is just the color of the background that I set in AppDelegate.

self.window.backgroundColor = [UIColor whiteColor];`

When I debug it, the RESide menu is presented in the completion block of the function showRightMenuViewController (a helper function provided by the RESide Menu library) but disappears at the end of the completion block.

-(void)showRightMenuViewController
{
    if (!self.rightMenuViewController) {
        return;
    }
    [self.rightMenuViewController beginAppearanceTransition:YES animated:NO];
    self.leftMenuViewController.view.hidden = YES;
    self.rightMenuViewController.view.hidden = NO;
    [self.view.window endEditing:YES];
    [self addContentButton];
    [self updateContentViewShadow];
    [self resetContentViewScale];

    [[UIApplication sharedApplication] beginIgnoringInteractionEvents];
    [UIView animateWithDuration:self.animationDuration animations:^{
        if (self.scaleContentView) {
            self.contentViewContainer.transform = CGAffineTransformMakeScale(self.contentViewScaleValue, self.contentViewScaleValue);
        } else {
            self.contentViewContainer.transform = CGAffineTransformIdentity;
        }
        self.contentViewContainer.center = CGPointMake((UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) ? -self.contentViewInLandscapeOffsetCenterX : -self.contentViewInPortraitOffsetCenterX), self.contentViewContainer.center.y);

        self.menuViewContainer.alpha = !self.fadeMenuView ?: 1.0f;
        self.contentViewContainer.alpha = self.contentViewFadeOutAlpha;
        self.menuViewContainer.transform = CGAffineTransformIdentity;
        if (self.scaleBackgroundImageView)
            self.backgroundImageView.transform = CGAffineTransformIdentity;

    } completion:^(BOOL finished) {
        // at this line RESide menu appears!
        [self.rightMenuViewController endAppearanceTransition];
        if (!self.rightMenuVisible && [self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:didShowMenuViewController:)]) {
            [self.delegate sideMenu:self didShowMenuViewController:self.rightMenuViewController];
        }

        self.visible = !(self.contentViewContainer.frame.size.width == self.view.bounds.size.width && self.contentViewContainer.frame.size.height == self.view.bounds.size.height && self.contentViewContainer.frame.origin.x == 0 && self.contentViewContainer.frame.origin.y == 0);
        self.rightMenuVisible = self.visible;
        [[UIApplication sharedApplication] endIgnoringInteractionEvents];
        [self addContentViewControllerMotionEffects];
        // RESide menu is still here, on the view hierarchy, everything is good
        // after this RESide menu disappears
    }];

    [self statusBarNeedsAppearanceUpdate];
}

I am not sure if I am setting the ContentViewController wrongly. I switched it to self in my desired viewcontroller because I assume that it is the viewcontroller displayed off to the side when my RESide menu is being displayed. Switching it to self.navigationController throws an error in adding a childViewController, while not switching it at all causes nothing to happen, my viewcontroller loads without displaying the RESide menu.

My storyboard structure is a little complicated, so maybe that is a cause of the problem that I don't understand. I have a navigation controller that is root VC to the next VC, a login page, then a modal segue to another navigation controller that is root VC to my particular viewcontroller.

Thank you! Please let me know if anything is unclear, I will try to clarify it.