ios - 如何创建仅在使用 SwiftUI 打开应用程序时出现的警报?
问题描述
我是应用程序开发的新手,最近创建了一个名为靶心的游戏。
我想在首次打开应用程序时显示一条警报,向用户提供有关他们将要玩的游戏的说明。
我在没有按钮的情况下在 swiftUI 中创建此警报时遇到问题,想知道是否有人可以帮助我解决此问题。
PS - 我正在使用 Xcode 11
谢谢
解决方案
我不是 SwiftUI 专家,但这对我有用:
import SwiftUI
struct ContentView: View {
// In the future, you can use this var to control whether or not to show an alert based on some other condition.
@State var alertShouldBeShown = true
var body: some View {
// attach the alert to the last view in your view hierarchy
Text("Hello, World!").alert(isPresented: $alertShouldBeShown, content: {
Alert(title: Text("Alert:"),
message: Text("This is the alert. :)"),
dismissButton: Alert.Button.default(
Text("OK"), action: {
//
}
)
)
})
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
推荐阅读
- azure-ad-graph-api - Microsoft Teams graph api(获取频道)不会以用户默认语言返回数据,它总是以英语返回数据?
- python - 从代码运行时静音类自动调试模式
- javascript - 如何在 ES6 中创建 for...of 实例?
- c++ - Cocos2d-x v4.0 在带有 Xcode 12、Xcode 12.1、Xcode 12.2 的 iPhone 模拟器中崩溃
- mysql - 如何在 VB.Net 中分别检查是否有 2 个或更多查询正在执行
- ios - 我在 ios webview 应用程序中使用 iframe 加载网站,但窗口已打开
- css - 删除手机的完美滚动条
- java - 使用 Java 从服务器主机存储和检索数据
- assembly - 为什么在摩托罗拉 68k 中,对于非常大的循环计数,dbra 如此之快?
- javascript - 如何删除数组中的重复元素?