Push segue in xcode with no animation

XcodeAnimationSegue

Xcode Problem Overview


I am using normal storyboarding and push segues in xcode, but I want to have segues that just appear the next view, not slide the next view (as in when you use a tab bar and the next view just appears).

Is there a nice simple way to have normal push segues just "appear" and not "slide", without needing to add custom segues?

Everything is working completely fine, I just want to remove that slide animation between the views.

Xcode Solutions


Solution 1 - Xcode

I was able to do this by creating a custom segue (based on this link).

  1. Create a new segue class (see below).
  2. Open your Storyboard and select the segue.
  3. Set the class to PushNoAnimationSegue (or whatever you decided to call it).

Specify segue class in Xcode

Swift 4

import UIKit

/*
 Move to the next screen without an animation.
 */
class PushNoAnimationSegue: UIStoryboardSegue {

    override func perform() {
        self.source.navigationController?.pushViewController(self.destination, animated: false)
    }
}

Objective C

PushNoAnimationSegue.h

#import <UIKit/UIKit.h>

/*
 Move to the next screen without an animation.
 */
@interface PushNoAnimationSegue : UIStoryboardSegue

@end

PushNoAnimationSegue.m

#import "PushNoAnimationSegue.h"

@implementation PushNoAnimationSegue

- (void)perform {

    [self.sourceViewController.navigationController pushViewController:self.destinationViewController animated:NO];
}

@end

Solution 2 - Xcode

You can uncheck "Animates" in Interface Builder for iOS 9

enter image description here

Solution 3 - Xcode

Ian's answer works great!

Here's a Swift version of the Segue, if anyone needs:

UPDATED FOR SWIFT 5, MAY 2020

PushNoAnimationSegue.swift

import UIKit

/// Move to the next screen without an animation
class PushNoAnimationSegue: UIStoryboardSegue {
override func perform() {
    if let navigation = source.navigationController {
        navigation.pushViewController(destination as UIViewController, animated: false)
    }
}

Solution 4 - Xcode

I have now managed to do this using the following code:

CreditsViewController *creditspage = [self.storyboard instantiateViewControllerWithIdentifier:@"Credits"];
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:YES];
[self.navigationController pushViewController:creditspage animated:NO];
[UIView commitAnimations];

Hope this helps someone else!

Solution 5 - Xcode

Here's the Swift version adapted to modally present a ViewController without animation:

import UIKit

/// Present the next screen without an animation.
class ModalNoAnimationSegue: UIStoryboardSegue {
    
    override func perform() {
        self.sourceViewController.presentViewController(
            self.destinationViewController as! UIViewController,
            animated: false,
            completion: nil)
    }
    
}

Solution 6 - Xcode

answer using Swift3 -

for "push" segue:

class PushNoAnimationSegue: UIStoryboardSegue
{
    override func perform()
    {
       source.navigationController?.pushViewController(destination, animated: false)
    }
}

for "modal" segue:

class ModalNoAnimationSegue: UIStoryboardSegue
{
    override func perform() {
        self.source.present(destination, animated: false, completion: nil)
    }
}

Solution 7 - Xcode

For anyone using Xamarin iOS your custom segue class needs to look like this:

[Register ("PushNoAnimationSegue")]
public class PushNoAnimationSegue : UIStoryboardSegue
{
	public PushNoAnimationSegue(IntPtr handle) : base (handle)
	{

	}

	public override void Perform ()
	{
		SourceViewController.NavigationController.PushViewController (DestinationViewController, false);
	}
}

Don't forget you still need set a custom segue in your story board and set the class to the PushNoAnimationSegue class.

Solution 8 - Xcode

Just set animated false on UINavigationController.pushViewController in Swift

self.navigationController!.pushViewController(viewController, animated: false)

Solution 9 - Xcode

For me, the easiest way to do so is :

UIView.performWithoutAnimation { 
        
        self.performSegueWithIdentifier("yourSegueIdentifier", sender: nil)

    }

Available from iOS 7.0

Solution 10 - Xcode

I'm using Visual Studio w/ Xamarin, and the designer doesn't provide the "Animates" checkmark in dtochetto's answer.

Note that the XCode designer will apply the following attribute to the segue element in the .storyboard file: animates="NO"

I manually edited the .storyboard file and added animates="NO" to the segue element(s), and it worked for me.

Example:

 <segue id="1234" destination="ZB0-vP-ctU" kind="modal" modalTransitionStyle="crossDissolve" animates="NO" identifier="screen1ToScreen2"/>

Solution 11 - Xcode

PUSH WITHOUT ANIMATION : Swift Here is what worked for me.

import ObjectiveC

private var AssociatedObjectHandle: UInt8 = 0
    extension UIViewController {
    
        var isAnimationRequired:Bool {
            get {
        return (objc_getAssociatedObject(self, &AssociatedObjectHandle) as? Bool) ?? true
            }
            set {
                objc_setAssociatedObject(self, &AssociatedObjectHandle, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
            }
        }
    }
    
    -------------------- SilencePushSegue --------------------
    
class SilencePushSegue: UIStoryboardSegue {
    
    override func perform() {
        if self.source.isAnimationRequired == false {
            self.source.navigationController?.pushViewController(self.destination, animated: false)
        }else{
            self.source.navigationController?.pushViewController(self.destination, animated: true)
        }
    }
}

Usage : Set the segue class from storyboard as shown in picture. set the isAnimationRequired from your viewcontroller to false from where you want to call performSegue, when you want to push segue without animation and set back to true after calling self.performSegue. Best of luck....

DispatchQueue.main.async {
                self.isAnimationRequired = false
                self.performSegue(withIdentifier: "showAllOrders", sender: self);
                self.isAnimationRequired = true
            }

[![set the segue class from storyboard as shown in picture.][1]][1] [1]: https://i.stack.imgur.com/6DmCm.png

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionR2D2View Question on Stackoverflow
Solution 1 - XcodeIanView Answer on Stackoverflow
Solution 2 - XcodedtochettoView Answer on Stackoverflow
Solution 3 - XcodezaviéView Answer on Stackoverflow
Solution 4 - XcodeR2D2View Answer on Stackoverflow
Solution 5 - XcodeDaniel McLeanView Answer on Stackoverflow
Solution 6 - XcodeelkorbView Answer on Stackoverflow
Solution 7 - XcodeJacobKView Answer on Stackoverflow
Solution 8 - XcodeMichaelView Answer on Stackoverflow
Solution 9 - XcodeLironXYZView Answer on Stackoverflow
Solution 10 - XcodeWesView Answer on Stackoverflow
Solution 11 - XcodeUsmanView Answer on Stackoverflow