Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source view controller hides during custom segue

I'm trying to make a custom segue so that the destination view controller slides down from the top.

I wrote my code according to the example from the documentation.

The problem is that when the segue is executed, the source view controller goes black, and then the animation occurs. How can I prevent the source view controller from going black?

(I already tried implementing the solution presented in this answer but the screen either goes black after the transition, or reverts to the source view controller.)

Here's my code:

-(void)perform{

    UIViewController *splashScreen = self.sourceViewController;
    UIViewController *mainScreen = self.destinationViewController;

    //Place the destination VC above the visible area        
    mainScreen.view.center = CGPointMake(mainScreen.view.center.x,
                                          mainScreen.view.center.y-600);

    //Animation to move the VC down into the visible area
    [UIView animateWithDuration:1
                     animations:^{
                         mainScreen.view.center = CGPointMake(mainScreen.view.center.x, [[UIScreen mainScreen] bounds].size.height/2 );
                     }
     ];

    [splashScreen presentModalViewController:mainScreen animated:NO];
}
like image 591
Eric Avatar asked Oct 22 '22 15:10

Eric


1 Answers

The reason that your source view controller seems to be hidden is that the destination view controller is presented right away.

When you are writing custom segues you don't have both views available at the same time. You could either

  • push view controller, add the source view to the destination view controller and animate
  • add the destination view to the source view controller and animate, then push view controller
  • push to an in-between view controller, add both views, animate, push to the destination view controller.

In all the above cases where I say push view controllers you could instead present view controllers modally. In fact that might be more suitable for the in-between view controller solution.

like image 187
David Rönnqvist Avatar answered Nov 04 '22 00:11

David Rönnqvist