Push segue in xcode with no animation

2019-01-13 01:50发布

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.

11条回答
你好瞎i
2楼-- · 2019-01-13 02:27

Ian's answer works great!

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

PushNoAnimationSegue.swift

import UIKit

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

    override func perform() {
        let source = sourceViewController as UIViewController
        if let navigation = source.navigationController {
            navigation.pushViewController(destinationViewController as UIViewController, animated: false)
        }
    }

}
查看更多
Explosion°爆炸
3楼-- · 2019-01-13 02:30

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"/>
查看更多
【Aperson】
4楼-- · 2019-01-13 02:32

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

enter image description here

查看更多
霸刀☆藐视天下
5楼-- · 2019-01-13 02:37

Just set animated false on UINavigationController.pushViewController in Swift

self.navigationController!.pushViewController(viewController, animated: false)
查看更多
男人必须洒脱
6楼-- · 2019-01-13 02:38

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
查看更多
走好不送
7楼-- · 2019-01-13 02:38

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!

查看更多
登录 后发表回答