When investigating a memory leak, I found a problem with the method of calling setRootViewController: inside the transition animation block:
[UIView transitionWithView:self.window duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{ self.window.rootViewController = newController; } completion:nil];
If the old view controller (the one that is being replaced) is currently a different view controller, then the code above does not remove the presented view from the view hierarchy.
That is, this sequence of operations ...
- X becomes Root View Controller
- X represents Y, so Y is the view on the screen
- Using
transitionWithView: to make Z the new root view controller
... looks good to the user, but the Debug View Hierarchy tool will show that the Y image is still behind the Z view, inside the UITransitionView . That is, after three steps above, the presentation hierarchy:
- UIWindow
- UITransitionView
- UIView (view Z)
I suspect this is a problem because during the transition, view X is not actually part of the view hierarchy.
If I send dismissViewControllerAnimated:NO to X just before transitionWithView: resulting view hierarchy:
- UIWindow
- UIView (view X)
- UIView (view Z)
If I send dismissViewControllerAnimated: (YES or NO) to X, go through the completion: block, then the view hierarchy is correct. Unfortunately, this interferes with the animation. If you revive the dismissal, he spends time; if he does not revive, he looks broken.
I am trying to use other approaches (for example, creating a new view controller class as my root view controller), but have not found anything. I will update this question when I go.
The ultimate goal is to move from the presented view to the new root view controller directly and without leaving a hierarchy of inaction.
ios cocoa-touch uiviewcontroller core-animation
benzado Nov 05 '14 at 17:08 2014-11-05 17:08
source share