Hi all,
I'm using a custom view controller which allows to add (show) child view controllers. Currently I'm using the following scheme to add a view controller:
- (void)addViewController:(UIViewController*)viewController
{
[self addChildViewController:viewController];
viewController.view.frame = [self _startFrameFor:viewController];
[self.view addSubview:viewController.view];
[UIView animateWithDuration:ANIMATION_DURATION
animations:^{
viewController.view.frame = [self _endFrameFor:viewController];
} completion:^(BOOL finished) {
[viewController didMoveToParentViewController:self];
}];
}This did it's job until iPhone X and its safeAreaInsets came into play.
If, for example, the iPhone X is in landscape mode and I add a view controller to the left of the container view controller, the view (e.g. a UITableViewController) is moved in without respecting any safeAreaInsets. After viewDidAppear being called, the view relayouts with the correct safeAreaInsets.
Just out of curiosity I checked what happens when I show the child view controller with a cutsom presentation. So I setup this very simple animator:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIView* containerView = transitionContext.containerView;
UIView* toView = [transitionContext viewForKey:UITransitionContextToViewKey];
toView.frame = self.sourceFrame;
[containerView addSubview:toView];
[UIView animateWithDuration:ANIMATION_DURATION
animations:^{
toView.frame = self.targetFrame;
} completion:^(BOOL finished) {
[transitionContext completeTransition:finished];
}];
}and presented the child view controller with a
modalPresentationStyle = UIModalPresentationCustom. This way the child view controller is animated in already respecting any safeAreaInstes. But of course I don't want to modally present the view controller.Any idea how to correctly animate adding or removing a child view controller to / from a custom container view controller.
Dirk.