iOS 8 - Screen blank after dismissing view controller with custom presentation
When dismissing various view controllers using UIModalPresentationCustom
, the screen turns black after the view controller is dismissed, as if all the view controllers had been removed from the view hierarchy.
The transitioning delegate is set properly, the animationControllerForPresentedController is asked for and passed correctly, and the transition is completed once the animation is over.
This exact code works perfectly when compiled with the iOS 7 SDK, but is broken when compiled with iOS 8b5
This is because you are most likely adding both the presenting
[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]
and the presented
[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]
view controllers to your containerView in the (void)animateTransition:(id )transitionContext method of your animation controller. Since you are using a custom modal presentation, the presenting view controller is still shown beneath the presented view controller. Now since it's still visible you don't need to add it to the container view. Instead only add the presented view controller to the containerView. Should look something like this inside of your animateTransition: method
UIView *containerView = [transitionContext containerView];
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
// Boolean value to determine presentation or dismissal animation
if (self.presenting){
[transitionContext.containerView addSubview:toViewController.view];
// Your presenting animation code
} else {
// Your dismissal animation code
}
This is the kind of question that the high-votes & accepted answer mislead people. Long words short.
Firstly, don't use UIModalPresentationCustom, it's not what it sounds like. (detail)
Secondly, there is a new method to retrieve from/to Views in animateTransition, don't use something like 'fromVC.view' anymore. (why)
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];
UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];
//swift
let fromVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)
let toVC = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)
let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)
let toView = transitionContext.viewForKey(UITransitionContextToViewKey)
Now the black screen should go away.