问题
My App uses GeometryReader with some padding to setup a View frame dimension inside a NavigationView.
Since iOS 14 i get the following error message:
Invalid frame dimension (negative or non-finite)
Here is some example code to test:
import SwiftUI
struct ContentView: View {
let padding:CGFloat = 16.0
var body: some View {
NavigationView {
GeometryReader { p in
Text("Hello, world!")
.frame(width: p.size.width - padding)
.padding()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Removing NavigationView fix the problem, but I need the current width and height of the container View inside the NavigationView.
Any suggestion?
回答1:
I think it might be a static analysis issue as .frame(width: p.size.width - padding)
could result in a negative value. Try:
.frame(width: abs(p.size.width - padding))
来源:https://stackoverflow.com/questions/64051332/ios-14-invalid-frame-dimension-negative-or-non-finite