在 xcode 中推入 segue,不使用动画

我在 xcode 中使用的是普通的故事板和推送接口,但是我希望接口只显示下一个视图,而不是幻灯片下一个视图(比如当你使用标签栏时,下一个视图就会出现)。

有没有一个很好的简单的方法,让普通的推转接口只是“出现”,而不是“幻灯片”,而不需要添加自定义接口?

一切都工作完全正常,我只是想删除之间的幻灯片动画视图。

37508 次浏览

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!

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

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)
}
}

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)
}


}

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.

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

enter image description here

Just set animated false on UINavigationController.pushViewController in Swift

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

For me, the easiest way to do so is :

UIView.performWithoutAnimation {


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


}

Available from iOS 7.0

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)
}
}

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"/>

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.