【发布时间】:2021-06-22 00:19:53
【问题描述】:
当我单击我的 SwiftUI 文本字段并打开键盘时,应用程序会缩小(显示在 video 中)。
我对此行为有两个疑问:
- 为什么会这样?
- 如何避免这种情况发生?
这是我的代码:
struct BestillView: View { // This view is put inside a tab view with .ignoresSafeArea
@State var navn = ""
@State var varsling = true
var body: some View {
NavigationView {
ZStack {
Color("BackgroundColor")
.ignoresSafeArea()
VStack {
Image("Liquid") // This is my image overlayed on the background, i suspect this may be the only element that actually gets zoomed out
.resizable()
.aspectRatio(contentMode: .fit)
.ignoresSafeArea()
Spacer()
}
VStack {
ZStack(alignment: .leading) { // This is where the text field i'm having trouble with is
Color("UnselectedColor")
.frame(height: 50)
.cornerRadius(20.0)
if navn.isEmpty { // I have a separate text element as the placeholder text so i can give it a custom color
Text("Navn")
.foregroundColor(Color("AccentColor"))
.padding()
}
TextField("", text: $navn)
.padding()
}
.frame(width: 300)
Spacer()
.frame(height: 20.0)
// I removed the rest of my code, I don't think it should be necessary in this question - it's only a NavigationLink and a Toggle
}
}
}
}
}
【问题讨论】:
标签: swift xcode swiftui keyboard textfield