Frostrar
Frostrar

Reputation: 337

Custom segue not working

I am trying to use a custom transition. I want a "cover vertical" transition from View Controller 1 to 2 and then have View Controller 2 (the middle one) slide back down again when moving to View Controller 3. Storyboard shown below:

https://i.sstatic.net/bJYXI.png

Im using the tutorial that is linked to from this post. And have also replaced the .m code with the code provided in the answer:

Xcode custom segue - Opposite of Cover Vertical (top to bottom) - COMPLETE NEWBIE

I have created a subclass of UIViewController and named it FromTopReplaceSegue. My .h and .m code is shown below:

.h

#import <UIKit/UIKit.h>

@interface FromTopReplaceSegue : UIViewController
@property(nonatomic, readonly) id sourceViewController;
@property(nonatomic, readonly) id destinationViewController;

@end

.m

#import "FromTopReplaceSegue.h"

@interface FromTopReplaceSegue ()

@end

@implementation FromTopReplaceSegue

-(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];
                     }];}

@end

When i try to run the simulator i can easily get from Controller View 1 to 2 but it crashes when i try to move from Controller view 2 to 3 using the custom segue.

Can anyone help.

Thank you so much in advance! Struggling here! :)

Upvotes: 0

Views: 552

Answers (1)

virtualnobi
virtualnobi

Reputation: 1180

Some time gone since my iOS days, but shouldn't the .h not define a subclass of a seque class instead of a viewcontroller? Like

@interface FromTopReplaceSegue : UIStoryboardSegue

You can read its documentation for some notes on subclassing as well...

Upvotes: 5

Related Questions