Xcode custom segue - Vertical cover opposite (top to bottom) - COMPLETE NEWBIE

I have been trying for some time to create a custom segue that does the back of a vertical cover (to create an animation of the effect from top to bottom). I looked at other questions, google and youtube, but cannot make them work. I am completely new to classes, etc., so any help in a walkthrough or video would be so good. I believe this url is trying to do something similar to what I want:

http://jrwren.wrenfam.com/blog/2012/02/01/storyboard-custom-segue-for-custom-pushviewcontroller-animation/ , I just can't get it to work.

If any of you know how to create a segment, which is the top and bottom versions of the cover of a vertical segment, can you help me?

+8
xcode segue
source share
7 answers

Well, you would like to create a subclass of UIStoryBoardSegue, as shown in the walkthrough, however, in the .m file (implementation) of the Storyboard class you will need the following code, as your - (void) execute: method -

-(void)perform{ UIViewController *sourceViewController = (UIViewController *) self.sourceViewController; UIViewController *destinationViewController = (UIViewController *) self.destinationViewController; [sourceViewController.view addSubview:destinationViewController.view]; [destinationViewController.view setFrame:sourceViewController.view.window.frame]; [destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, -sourceViewController.view.frame.size.height)]; [destinationViewController.view setAlpha:1.0]; [UIView animateWithDuration:0.75 delay:0.0 options:UIViewAnimationOptionTransitionFlipFromTop animations:^{ [destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, 0)]; [destinationViewController.view setAlpha:1.0]; } completion:^(BOOL finished){ [destinationViewController.view removeFromSuperview]; [sourceViewController presentViewController:destinationViewController animated:NO completion:nil]; }];} 

Hope this helps.

+8
source share

Based on @ dmason82's answer, translate to Swift and simplify a bit, this works for me:

 class UIStoryboardSegueFromTop: UIStoryboardSegue { override func perform() { let src = self.sourceViewController as UIViewController let dst = self.destinationViewController as UIViewController src.view.superview?.insertSubview(dst.view, aboveSubview: src.view) dst.view.transform = CGAffineTransformMakeTranslation(0, -src.view.frame.size.height) UIView.animateWithDuration(1.0, animations: { dst.view.transform = CGAffineTransformMakeTranslation(0, 0) }) { (Finished) in src.presentViewController(dst, animated: false, completion: nil) } } } 
+3
source share

Here is my implementation of the opposite cover Vertical Segue using storyboards

https://github.com/viccarre/OppositeCoverVerticalSegue

+2
source share

Hi, I just tried the other two answers, but it does not work as you ask. To create a custom segue that searches for the exact back side of the vertical cover (modal segue default), I created this code:

 - (void)perform { UIViewController *sourceViewController = self.sourceViewController; UIViewController *destinationViewController = self.destinationViewController; [sourceViewController presentViewController:destinationViewController animated:NO completion:nil]; [destinationViewController.view addSubview:sourceViewController.view]; [sourceViewController.view setTransform:CGAffineTransformMakeTranslation(0, 0)]; [sourceViewController.view setAlpha:1.0]; [UIView animateWithDuration:0.75 delay:0.0 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{ [sourceViewController.view setTransform:CGAffineTransformMakeTranslation(0,destinationViewController.view.frame.size.height)]; [sourceViewController.view setAlpha:1.0]; } completion:^(BOOL finished){ [sourceViewController.view removeFromSuperview]; }]; } @end 
+1
source share

To end the dmason answer and turn off your controller in the opposite direction - go back to where it came from, do it in the presented view controller:

 [UIView animateWithDuration:0.75 delay:0.0 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{ [self.view setTransform:CGAffineTransformMakeTranslation(0, -self.view.frame.size.height)]; } completion:^(BOOL finished){ [self dismissViewControllerAnimated:NO completion:nil]; } ]; 

Bergy's answer did not help me.

+1
source share

Dmason's answer is great, and if you want to add a spin segment so that your modal animates correctly when it is closed, your action might look like this (in a new custom segue class)

 - (void)perform { UIViewController *sourceViewController = self.sourceViewController; UIViewController *destinationViewController = self.destinationViewController; [sourceViewController dismissViewControllerAnimated:NO completion:nil]; [destinationViewController.view addSubview:sourceViewController.view]; [UIView animateWithDuration:0.75 animations:^{ sourceViewController.view.center = CGPointMake(sourceViewController.view.center.x, sourceViewController.view.center.y-600); } completion:^(BOOL finished){ [sourceViewController.view removeFromSuperview]; } ]; } 
0
source share

I advise you to use the Hero library for this. It adds a lot of animations and transitions, especially between dispatchers: https://github.com/lkzhao/Hero/blob/master/README.md There is a transition called β€œCover”, and you can choose the direction (left, top, right, bottom)

0
source share

All Articles