You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift中如何在Alert弹窗弹出后将其关闭?

Swift 5/iOS 15 实现Alert弹窗自动关闭的最简方法

我需要实现一个能自动关闭的简单Alert弹窗,当前弹窗通过以下代码展示:

present(alert, animated: true, completion: nil)

已找到适配Swift 5/iOS 15环境的最简解决方案,分享给有相同需求的开发者:

// 2秒后自动关闭弹窗
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0, execute: {
    alert.dismiss(animated: true, completion: nil)
})

内容的提问来源于stack exchange,提问作者Lionel Yu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 07:35:27