How to perform segue with no transition animation

22,122

Solution 1

Duplicate your segue in Storyboard and give the second one a different ID.

You can then change the transition in the new version.

Solution 2

 self.performSegueWithIdentifier("loginSegue",sender: nil)

enter image description here

Solution 3

I am using this snippet to request authorization in viewDidLoad:

[UIView setAnimationsEnabled:NO];
self.view.hidden = YES;

[self performSegueWithIdentifier:@"segue_auth" sender:self];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [UIView setAnimationsEnabled:YES];
    self.view.hidden = NO;
});

When authorized, back transition is animated as I want.

Solution 4

One more way we can

YourViewController *aYourViewController = [self.storyboard   instantiateViewControllerWithIdentifier:@"aYourViewControllerIdentifier"];
[self.navigationController pushViewController:aYourViewController animated:NO];

and add the @"aYourViewControllerIdentifier" to view controller in your storyboard.

Share:
22,122
voromax
Author by

voromax

I write code for the living.

Updated on June 10, 2020

Comments

  • voromax
    voromax about 4 years

    I have an application which starts with a navigation controller. This navigation controller can open modal view controller:

    - (void)openModalController:(id)sender
    {
        [self performSegueWithIdentifier:@"SegueIdentifier"];
    }
    

    But when the user opens an application using url scheme, I'd like to present the application with the modal controller opened. So I added some methods and tried:

    // Controller
    
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated]; // animated == NO in initial loading 
    
        if (_shouldOpenModalController) {
            [self openModalController:nil];
        }
    }
    
    - (void)setShouldOpenModalController:(BOOL)flag
    {
        _shouldOpenModalController = flag;
    }
    
    // AppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        if (launchOptions) {
            UINavigationController *nc = (UINavigationController *)self.window.rootViewController;
            MyViewController *c = (MyViewController *)[ns topViewController];
            [c setShouldOpenModalController];
        }
    }
    

    But here is a problem: the openModalController: performs segue with transition animation I setup in storyboard. How can it be done with no animation? Is there another approach for this task?

  • voromax
    voromax about 11 years
    To create one more segue to try to skip the transition animation on it... There must be other way, I'd rather open view controller manually than create custom segue transition with no animation.
  • Gordon Dove
    Gordon Dove about 11 years
    You don't need a custom segue, there is an 'animates' checkbox on the modal transition.
  • Aviel Gross
    Aviel Gross over 9 years
    Trying to create a new segue between the same view and VC only replace the existing segue... at least on Xcode 6.1 (not using size-classes)
  • ruliak
    ruliak almost 9 years
    This solution works in Xcode 6+, and others don't (segue duplication is not allowed).
  • k06a
    k06a almost 9 years
    @ruliak I am not duplicating segue. I think you wanna comment not this answer :)
  • davidethell
    davidethell over 8 years
    I wish I could vote twice. I've come back here a year later and used this method again! Forgot that I'd found it once already!
  • Igor de Lorenzi
    Igor de Lorenzi over 8 years
    I just would add this: wrap up the performSegueWithIdentifier:sender: message with dispatch_async(dispatch_get_main_queue(), ^{ /* performSegueWithIdentifier:sender: */ }); prevents the warning: "Unbalanced calls to begin/end appearance transitions for ...".
  • Kesava
    Kesava almost 8 years
    This is more of a hastle. If we already have a segue, we shouldnt be instantiating the view controller by code. The whole point of having a segue is to avoid instantiating the view controller in the code.
  • Geva
    Geva about 6 years
    That doesn't solve the issue of supporting two flow scenarios, one with animation and one without.