swift - 完全关闭中间的 View Controller

标签 swift uiviewcontroller dismiss removefromsuperview

我已经找了好几天了。问题是这样的: 我有一个主视图 Controller 。当它收到通知时,它会呈现一个 NotiViewController,名为 noti1,通过

`home.present(noti1, animated: true, completion: nil)`. 

15秒后,另一个通知到来,我得到顶部 View Controller topVC,呈现另一个NotiViewController,称为noti2,由

`topVC.present(noti2, animated: true, completion: nil)`.

每个 notiVC 都有一个计时器,等待 30 秒后自行关闭。现在我有 Home -> noti1 -> noti2

15 秒后,noti1 超时,必须被解雇。如何在不中断正在演示的 noti2 的情况下关闭它?

我试过了

`orderVC.beginAppearanceTransition(false, animated: false)
 orderVC.willMove(toParent: nil)
 orderVC.view.removeFromSuperview()
 orderVC.removeFromParent()
 orderVC.endAppearanceTransition()`

这些代码确实从屏幕上删除了 View ,但它留下了一个 UITransitionView ,这会阻止用户操作。

Blocking UITrainstionView(s)

此图像是在从 super View 等中删除 noti2 后拍摄的,因此有 2 个 UITransitionViews 正在呈现,阻止了用户操作。

有什么想法吗?非常感谢。

最佳答案

找到办法了。我不确定我是对还是错,但这是我的想法: View Controller 必须像以前呈现的那样被解雇。例如,如果您使用present(viewController,animated,completion)来呈现,则应该使用dismiss(animated,completion)来关闭。就我而言,问题是如果您关闭 View Controller ,所有 subview Controller 也将消失。

我解决问题的方法是使用另一种方式“显示”目标 View Controller : parentVC.view.addSubview(childVC.view) ParentVC.addChild(childVC) childVC.didMove(toParent:parentVC)

添加一些 View Controller 后,我得到了一个树parentVC -> child1 -> child2 -> child3...如果我想关闭child2,我的问题中的代码有效: child2.willMove(toParent: nil) child2.view.removeFromSuperview() child2.removeFromParent()

没有 UITransitionView 阻止用户操作,但它没有动画。对于我来说这已经足够好了。

关于swift - 完全关闭中间的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59278270/

相关文章:

ios - 来自应用程序委托(delegate)的自定义 segue

ios - 删除所有核心数据数据

iphone - 从头开始重新启动 iPhone 应用程序

swift - 将捕获的/图库图像从一个 ViewController 传递到另一个

ios - 如何从 iOS Swift 中的框架中关闭相机 Controller ?

ios - 关闭 viewController 后更新 outlets

ios - 如何在委托(delegate)函数中关闭 alertview - (void)alertView :(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

ios - 翻转 super View 后 UIButton 点击​​区域发生移动

ios - 当选择单元格时,TableVIew 中的 UIImage 会移动

objective-c - 将 Storyboard中的 UIViewController 更改为 UITableViewController?