IOS 8 - Screen saver after rejecting a view controller with custom presentation

When different view controllers are rejected using the UIModalPresentationCustom screen turns black after the view controller is rejected, as if all view managers were removed from the presentation hierarchy.

The rolling delegate is set correctly, the animationControllerForPresentedController function is requested and passed, and the transition completes after the animation finishes.

This exact code works great when compiling with the iOS 7 SDK, but when compiling with iOS 8b5

+58
ios objective-c cocoa-touch uikit ios8
Aug 31 '14 at 3:05
source share
7 answers

This is because you most likely add as a presentation

[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]

and submitted

[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]

map the controllers in your View container to the (void) animateTransition: (id) transitionContext method of your animation controller. Since you are using a special modal presentation, the presenting view controller is still displayed below the presented view controller . Now, since it is still visible, you do not need to add it to the container view. Instead, add only the presented view controller to the container. It should look something like this inside 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 } 
+151
Sep 26 '14 at 0:42
source share

This is the question that a highly rated voice and the accepted answer mislead people. Long words are short.

First , do not use the UIModalPresentationCustom, this is not what it looks like. ( in detail )

Secondly, there is a new method for extracting from / to a view in animateTransition, no longer use something like 'fromVC.view'. ( 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 disappear.

+11
Dec 05 '15 at 3:00
source share

I seem to be facing the same problem, I am using Xcode 6 beta5.

I searched on Google and found that someone had the same problem, and they said that this is a serious bug in iOS 8, so we hope that Apple can fix this in the near future.

https://github.com/TeehanLax/UIViewController-Transitions-Example/issues/5

+5
Aug 31 '14 at 8:47
source share

I added the code below to the transition completion block and it fixed it for me.

 [UIView animateWithDuration:[self transitionDuration:transitionContext] animations: ^{ // Animation code } completion: ^(BOOL finished) { // More of your code // Add the following line before completing the transition [[[UIApplication sharedApplication] keyWindow] sendSubviewToBack:toViewController.view]; // Complete the transition [transitionContext completeTransition:YES]; }]; 
+2
Sep 12 '14 at 18:54
source share

Perhaps the presentation hierarchy is wrong with the new Xcode, or maybe a little different from iOS8. This code worked for me. Add it by rejecting the controller in animateTransition: transitionContext mode.

 [[UIApplication sharedApplication].keyWindow addSubview:toViewController.view]; toViewController.view.userInteractionEnabled = YES; 
+2
Sep 28 '14 at 1:00 a.m.
source share

Quick tip: make sure your "From" UIViewController is what you expect.

  NSLog(@" FROM vc %@" , [[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey] description]); 

I had a similar error in my code in the past. You can easily pull the correct "From" VC context.

  UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; fromView = [[[fromVC childViewControllers] firstObject] view]; 
0
Mar 26 '15 at 4:02
source share

I had the same problem and the problem for me was that I did not set the final toViewController frame. See the following example from http://www.appcoda.com/custom-view-controller-transitions-tutorial/

 func animateTransition(transitionContext: UIViewControllerContextTransitioning) { let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)! let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)! let finalFrameForVC = transitionContext.finalFrameForViewController(toViewController) let containerView = transitionContext.containerView() let bounds = UIScreen.mainScreen().bounds toViewController.view.frame = CGRectOffset(finalFrameForVC, 0, bounds.size.height) containerView.addSubview(toViewController.view) UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: .CurveLinear, animations: { fromViewController.view.alpha = 0.5 toViewController.view.frame = finalFrameForVC }, completion: { finished in transitionContext.completeTransition(true) fromViewController.view.alpha = 1.0 }) } 
0
Nov 05 '16 at 17:02
source share



All Articles