iOS:关闭 View Controller 并推送新 View 而不在导航堆栈中显示当前 View

标签 ios objective-c swift uinavigationcontroller presentmodalviewcontroller

我有一个导航 Controller 堆栈,其中包含不同的可能 Controller 。

我想根据我推送到导航 Controller 的下一个 View ,在需要时以模态方式呈现一个 View Controller 。 (您可以将其视为用户登录验证屏幕......在移动到下一个屏幕之前验证用户。)

我能够成功地做到这一点

UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(contactPicker, animated: true, completion: nil)

并在我需要用

解雇时解雇它
UIApplication.sharedApplication().keyWindow?.rootViewController?.dismissViewControllerAnimated(false, completion: {
        self.navigationController.pushViewController(myNewVC, animated: true)
    })

我能够做到,但是从模态呈现的 View 到我的 (myNewvC) 新推送的下一个 View 的过渡并不完全是我想要的。当 View 关闭发生时,在我移动到下一个 View 之前,我可以看到我的来电屏幕一秒钟。我不想看到那个屏幕。可能吗?

(我也不想在导航堆栈中添加验证屏幕,因为该屏幕的目的不是导航堆栈的一部分)。

最佳答案

Apple 恰好在此处添加了完成 block ,以保护您免受未捕获的异常的影响,因为您想要做的事情可能会导致一个,因为您不能同时执行两个动画,也许有一些建议的解决方案:

尝试显示新 Controller ,然后在完成后将前一个 Controller 隐藏在完成 block 中(这样当用户关闭新 Controller 时,他将看不到前一个 Controller ),例如 假设你现在在 VC1 中,你想关闭它并显示 VC2,你可以在 objective-c 中使用下面的代码

[self presentViewController:VC2 animated:YES completion:^{
    [self dismissViewControllerAnimated:YES completion:nil];
}];

swift

self.presentViewController(VC2, animated: true) { () -> Void in
    self.dismissViewControllerAnimated(true, completion: nil)
}

或者您可以忽略它,如果用户不会关闭新 Controller ,那么他将永远不会看到旧 Controller ,但我认为这不会节省内存,因为 Controller 会卡在内存中。

关于iOS:关闭 View Controller 并推送新 View 而不在导航堆栈中显示当前 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35840209/

相关文章:

ios - RKManagedObjectRequestOperation objc_msgSend 期间 RestKit 崩溃

ios - 获取存储在应用程序文档文件夹中的文件内容

ios - dictionaryWithObjectsAndKeys 内循环

ios - alertAction ios 的自定义标题

ios - PFQueryTableViewController 快速按日期划分

swift - Swift 中的模态视图

ios - 适用于 iOS 8 的爱普生打印机 SDK

IOS 导出合规信息已更改

可以安全地将 objc_msgsend 转换为可变长度参数函数

ios - 压缩视频的尺寸/秒转换率是多少