问题描述
对我来说,即使在 stackOverflow 上提供了答案,我的视图仍然会被键盘推高。我两个都用:
对不起,如果这里缺少细节,这是我第一篇关于堆栈溢出的真实帖子
import SwiftUI
struct LoginView:查看{
// needed to get keyboard height when keyboard is shown
@StateObject private var keyboardHandler = KeyboardHandler()
//Sobald login gedrückt wurde und Erfolgreich war wird die Variable True
@State var isActive: Bool = false
@Observedobject private var loginVM = Loginviewmodel()
// change the var for the main animation
@Binding var userIsLoggedIn: Bool
// if a problem happens during the login process a message can be shown
@State var problemAccured = false
// message to present the user when error happend
@State var problemmessage = "Wrong password"
var body: some View {
vstack {
Spacer()
// stack with textfields
vstack(alignment: .leading) {
if problemAccured {
Text(problemmessage)
.font(.footnote)
.padding(.leading,35)
}
HStack(spacing: 12) {
Image(systemName: "envelope")
TextField("Enter your email address here",text: $loginVM.email)
.textFieldStyle(RoundedBorderTextFieldStyle())
.keyboardType(.emailAddress)
}
.padding(.bottom,3)
Divider()
// main password textField
HStack(spacing: 12) {
Image(systemName: "lock.shield")
SecureField("Enter your password here",text: $loginVM.password)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
.padding(.top,3)
}
.font(.subheadline)
.foregroundColor(.accentColor)
.padding()
.modifier(FrozenWindowModifier())
.frame(width: screen.width - 40)
.offset(y: keyboardHandler.keyboardHeight/10)
.animation(.easeInOut(duration: 0.3))
Spacer()
// login button
Button(action: {
// haptic Feedback when button is tapped
hapticpulse(Feedback: .rigid)
// login handleling
loginVM.login {
isActive = true
print("Login succeeded \(isActive)")
userIsLoggedIn = true
}
// Show textfield if errors accure
problemAccured = loginVM.checkerrors()
// Set Problem Message to ErrorMessage
problemmessage = loginVM.errorMessage
},label: {
HStack {
Text("Login!")
.foregroundColor(.primary)
Image(systemName: "person.fill.checkmark")
}
})
.padding()
// get the standard border and clipShape of the window
.modifier(WindowModifier())
// animation when keyboard is shown or not
.padding(.bottom,keyboardHandler.keyboardHeight)
.animation(.easeInOut(duration: 0.3))
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)