在没有动画的情况下在xcode中推送segue

时间:2013-04-25 07:47:21

标签: xcode animation segue

我正在使用普通的故事板并在xcode中推送segues,但我希望看到只显示下一个视图的segues,而不是滑动下一个视图(就像使用标签栏时出现的那样,下一个视图就会出现)。 / p>

是否有一种简单的方法可以让普通的推送段仅“显示”而不是“滑动”,而无需添加自定义段?

一切都工作得很好,我只想删除视图之间的幻灯片动画。

11 个答案:

答案 0 :(得分:141)

我可以通过创建自定义segue(基于this link)来完成此操作。

  1. 创建一个新的segue类(见下文)。
  2. 打开故事板并选择segue。
  3. 将课程设置为PushNoAnimationSegue(或您决定称之为的任何内容)。
  4. 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)
        }
    }
    

    目标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
    

答案 1 :(得分:46)

您可以取消选中&#34; Animates&#34;在Interface Builder for iOS 9中

enter image description here

答案 2 :(得分:35)

伊恩的回答非常好!

如果有人需要,这里是Swift版本的Segue:

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

}

答案 3 :(得分:6)

我现在已经设法使用以下代码执行此操作:

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

希望这有助于其他人!

答案 4 :(得分:3)

这是适用于模态呈现没有动画的ViewController的Swift版本:

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

}

答案 5 :(得分:2)

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

答案 6 :(得分:1)

对于使用Xamarin iOS的任何人,您的自定义segue类需要如下所示:

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

    }

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

不要忘记您仍然需要在故事板中设置自定义segue并将类设置为PushNoAnimationSegue类。

答案 7 :(得分:0)

对我来说,最简单的方法是:

UIView.performWithoutAnimation { 

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

    }

可从iOS 7.0获取

答案 8 :(得分:0)

我正在使用Visual Studio w / Xamarin,设计师没有在dtochetto的回答中提供“Animates”复选标记。

请注意,XCode设计器会将以下属性应用于.storyboard文件中的segue元素:animates =“NO”

我手动编辑了.storyboard文件,并在segue元素中添加了animates =“NO”,这对我有用。

示例:

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

答案 9 :(得分:0)

无需动画即可推送:迅速这是对我有用的东西。

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

用法:从情节提要中设置segue类,如图所示。当您想在没有动画的情况下推送segue,并在调用self.performSegue之后将其设置为true时,将ViewController中的isAnimationRequired设置为false。祝你好运......

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.

答案 10 :(得分:-1)

在Swift中的animated上设置UINavigationController.pushViewController false

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