Open sophyandres opened 11 years ago
I had the same problem. My solution for now was to modify presentView so I can send along the current viewController among the parameters. Then, in the same method, instead of self.rootViewController = window.rootViewController; I set self.rootViewController = viewController; Where viewController is the current viewController. Seems to work just fine... Another catch though; if your "current" viewController is not the rootController (as it seems to be the case), chances are dismissing the popup will set your current viewController as the rootController. You may need to adapt to this situation also, maybe change a bit the way the popup is presented and dismissed. But I guess this is not an issue in current recommended application flow.
My solution is way simpler:
if (window.rootViewController.presentedViewController) self.rootViewController = window.rootViewController.presentedViewController; else self.rootViewController = window.rootViewController;
What do you think?
Ok my solution doesnt work very well... the rootVC is deallocated . There is a need to keep it in memory still to go back
My issue is when i show a popup from a modal VC.
It certainly might be a good idea to get the presented view controller like that instead of passing it along like a parameter. If it works, then go for it. But yes, there is a problem when you try to dismiss the popup. I finally skipped messing with the rootVC altogether. So I set self.rootViewController as the current presented view controller, commented the line: //window.rootViewController = self The problem with this is that you lose the reference to the popup view when you try dismiss it, as it is not the rootViewController anymore. But the popup view should be the one on top of the stack. So I changed the dismiss methods to this:
(void)dismiss { UIWindow *window;
window = [UIApplication sharedApplication].keyWindow; UIViewController *topController = window.rootViewController;
while (topController.presentedViewController) { topController = topController.presentedViewController; } if([topController isKindOfClass:[ASDepthModalViewController class]]) { ASDepthModalViewController *controller;
controller = (ASDepthModalViewController *)topController;
[controller dismiss];
} }
(void)dismiss { [UIView animateWithDuration:kModalViewAnimationDuration animations:^{ self.coverView.alpha = 0; self.rootViewController.view.transform = CGAffineTransformIdentity; self.popupView.transform = self.initialPopupTransform; self.blurView.alpha = 0; } completion:^(BOOL finished) { [self.rootViewController.view.layer setMasksToBounds:NO]; [self.blurView removeFromSuperview]; //[self restoreRootViewController]; <- no need to restore it anymore self.rootViewController.view.layer.cornerRadius = 0;
if (self.completionHandler) {
self.completionHandler();
}
[self dismissViewControllerAnimated:NO completion:nil];
}];
}
It's convoluted but it works for me, as I'm stuck with a project with no storyboards nor any of the new fancy ways to navigate through views...
The issue is that ASDepthmodal should be presented from our vc and not added as the root VC. Then when dismissed it would return to the previous VC without any problem.
This would involve a little of architecture change to the whole class.
Hi, I encountered an issue when trying to implement this in my app. The background view is the root view controller not the viewcontroller from where I started the action, and when I close the popup it redirects to the root view controller of the application. Can you help?