ios - X秒后关闭模态ViewController

标签 ios swift

我打开了一个登录模式UIViewController,然后在60秒钟内模态显示第二个“谢谢” Viewcontroller,然后关闭它,但是我可以弄清楚如何在SWIFT中执行此操作。 (在Objectiv C中很容易)

这是我的代码,用于在关闭第一个代码后打开“Thank you viewcontroller”。

        weak var pvc = self.presentingViewController
    self.dismiss(animated: true, completion: {
        let thankYouExistingVC = self.storyboard?.instantiateViewController(identifier: "ThankYouExistingVC") as! ThankYouExistingVC
        pvc?.present(thankYouExistingVC, animated: true, completion: nil)
    })

最佳答案

您可以使用DisaptchQueue来做到这一点:

    DispatchQueue.main.asyncAfter(deadline: .now() + 60) {
        // Do whatever you want
        theViewControllerToDismiss.dismiss(animated:true, completion: nil)
    }

关于ios - X秒后关闭模态ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59967814/

相关文章:

ios - 使用 Swift 从 HealthKit 读取日期间隔的步骤

swift - 为什么在 Swift 中调用两次方法时 GeoFire Query 仅填充数组?

ios - NativeScript - 使用 iBeacon 重启应用程序,AppDelegate 必须实现窗口属性

iOS UIpageviewcontroller 详见 uisplitviewcontroller。忽略后平移手势

ios - 使用 xCode 4.6 在 iOS 应用程序中记录突然停止工作

ios - swift 中的 alertControllers

ios - 将 REST URL 模式映射到 Siesta 框架的模型对象的最佳方法是什么?

ios - UITableViewCell内容滚动后消失

ios - 使应用程序出现在共享面板中以接受来自其他应用程序的选定文本

iOS 本地通知在锁屏时不播放声音