ios 如何在没有过渡动画的情况下执行转场

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16193612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:19:38  来源:igfitidea点击:

How to perform segue with no transition animation

iphoneiosipadstoryboard

提问by voromax

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:

但是当用户使用 url 方案打开应用程序时,我想在打开模态控制器的情况下显示应用程序。所以我添加了一些方法并尝试:

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

但这里有一个问题:openModalController:我在故事板中设置了带有过渡动画的执行转场。没有动画怎么能做到呢?这项任务还有另一种方法吗?

回答by Gordon Dove

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

在 Storyboard 中复制您的 segue 并为第二个指定不同的 ID。

You can then change the transition in the new version.

然后,您可以在新版本中更改过渡。

回答by keithics

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

enter image description here

在此处输入图片说明

回答by k06a

I am using this snippet to request authorization in viewDidLoad:

我正在使用此代码段请求授权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.

获得授权后,后退过渡按我的需要进行动画处理。

回答by Shahid Aslam

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.

@"aYourViewControllerIdentifier"在故事板中添加查看控制器。