【发布时间】:2022-01-11 19:12:41
【问题描述】:
大家好,我是 SwiftUI 的新手。只有在检查了一个条件后,我才需要展示一个包含两个文本字段的视图。
示例 .. 当用户按下登录按钮时,我需要应用程序检查数据库中是否存在用户。如果用户存在,他可以访问该应用程序,否则他必须显示一个必须输入他的姓名和姓氏的视图。
对于UIKit,我用它来展示structure 或class
self.present(userFound ? Home() : UserNameInfo(), animated: true, completion: nil)
但是对于SwiftUI,我不知道如何解决这个问题。
你能帮我吗?
我的代码
var body: some View {
ZStack(alignment: .top) {
Color(.black).ignoresSafeArea()
gradientBackground().ignoresSafeArea()
VStack(alignment: .center, spacing: 25) {
Spacer()
logoStack()
// Messaggio di benvenuto
VStack(alignment: .leading, spacing: 15) {
Text("Effettua l'accesso al tuo account")
.font(.title2.bold())
Text("Riserva un momento esclusivo prenotando un taglio tradizionale oppure una rasatura con panni caldi e trattamenti viso")
.font(.callout.weight(.light))
}
.foregroundColor(.white)
//.dynamicTypeSize(.medium)
// Apple Sign In Button
SignInWithAppleView()
.frame(width: screen.size.width - 56)
.frame(height: 45, alignment: .center)
.onTapGesture(perform: showAppleLoginView)
// Divisore
Divider().background(.gray)
// Messaggio sull'accettazione della Privacy e delle Condizioni di utilizzo
VStack(spacing: 5) {
Text("Continuando dichiaro di accettare le ")
.multilineTextAlignment(.center)
HStack(spacing: 0) {
Button("Condizioni di Utilizzo") {}
.foregroundColor(.white)
.font(.footnote.bold())
Text(" ed i ")
Button("Termini sulla Privacy") {}
.foregroundColor(.white)
.font(.footnote.bold())
Text(".")
}
}
.foregroundColor(.gray)
.font(.footnote)
.padding(.bottom, 25)
}
.padding(.horizontal)
}
private func showAppleLoginView() {
// Show modalview if user not exist in Firebase
}
// MARK: - Apple Sign In Button View Representable
struct SignInWithAppleView: UIViewRepresentable {
typealias UIViewType = ASAuthorizationAppleIDButton
func makeUIView(context: Context) -> UIViewType {
ASAuthorizationAppleIDButton(type: .signIn, style: .white)
}
func updateUIView(_ uiView: UIViewType, context: Context) {}
}
【问题讨论】:
标签: ios class if-statement swiftui presentmodalviewcontroller