【发布时间】:2019-11-05 14:03:22
【问题描述】:
我的 SwiftUI 应用程序上的 textField 被切断了。但并非每次都会发生。这似乎是随机发生的。
这是我正在使用的代码:
var body: some View {
VStack {
Spacer()
// Target row
HStack {
Text("Put the bullseye as close as you can to:")
Text("\(target)")
}
Spacer()
// Slider row
HStack {
Text("1")
Slider(value: $sliderValue, in: 1...100) {_ in
print(self.sliderValue)
}
Text("100")
}
Spacer()
// Hit me button row
Button(action: {
print("Button pressed")
self.alertIsVisible = true
}) {
Text(/*@START_MENU_TOKEN@*/"Hit Me!"/*@END_MENU_TOKEN@*/)
}
.alert(isPresented: $alertIsVisible) { () -> Alert in
let roundedValue = Int(sliderValue.rounded())
let score = pointsForCurrentRound()
return Alert(title: Text("Hello there!"), message: Text("The slider's value is \(roundedValue)!\n" +
"You scored \(score) points this round"
), dismissButton: .default(Text("Awesome")))
}
Spacer()
// Score and start over button row
HStack {
Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/) {
Text("Start Over")
}
Spacer()
Text("Score:")
Text("999999")
Spacer()
Text("Round:")
Text("999")
Spacer()
Button(action: /*@START_MENU_TOKEN@*/{}/*@END_MENU_TOKEN@*/) {
Text("Info")
}
}
.padding(.bottom, 20)
}
}
我尝试在文本字段的尾随和目标之前添加填充。我尝试在目标的前沿添加填充。我尝试在文本字段上使用 frame 方法来添加最小长度。这些都不起作用。有什么想法吗?
谢谢
【问题讨论】:
-
您使用的是哪个 Xcode 版本?我使用的是 Xcode 11.1 官方,并且在同一个项目上工作过,它在 iOS 13.1 及更高版本中已修复。
-
感谢您的回复。我正在使用最新版本的 Xcode 11.2 版。 iOS 13.1 及更高版本中修复了什么?
-
啊,所以在 iOS 13.1 及更高版本中,Text 根据其大小占用整个空间,而不是截断。你能告诉我它是什么时候随机发生的,在预览版还是模拟器/真实设备中?
-
它发生在预览版和模拟器中。我还没有在真机上试过。
-
我刚刚重新安装了 11.1 并试用了该应用程序。文本不再中断。所以一定是11.2中的东西。我会提交错误报告。谢谢你帮我解决这个问题。
标签: swiftui