如何解决 SwiftUI 视图约束冲突?

Fre*_*Lee 6 ios nslayoutconstraint swiftui

我正在玩弄 SwiftUI 中的图像显示,并决定附加警报以在找不到图像时激活。

以下是缩略代码:

struct ContentView: View {
    ...
    @State var image: URLImage = URLImage()
    ...
    @State var showActionSheet = true

    var body: some View {
        ZStack {
            Color.green
            NavigationView {
                VStack {
                    Button(action: {
                        self.url = "https://xxxx.org/\(Int.random(in: 0 ..< 10)).png"
                        self.image.imageLoader.load(url: URL(string: self.url)!)
                    }) {
                        Text("Get Random Image")
                    }
                    image.actionSheet(isPresented: $showActionSheet) {
                        ActionSheet(title: Text("Action Time"), message: Text("Greetings Ric!"), buttons:
                            [.default(Text("First Button"), action: {
                                print("First Button")
                        })])
                    }
                }.navigationBarTitle(Text("Ric's Images"))
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我将“showAlertSheet”标志设置为“true”时,我会收到警报,但也会收到编译器的约束投诉:

2019-11-25 12:41:21.628064-0800 GetImages[32413:1078621] [LayoutConstraints] 无法同时满足约束。可能以下列表中的至少一项约束是您不想要的。试试这个: (1) 查看每个约束并尝试找出您不期望的;(2) 找到添加不需要的约束或约束的代码并修复它。( "" )

将尝试通过打破约束来恢复

在 UIViewAlertForUnsatisfiableConstraints 处创建一个符号断点以在调试器中捕获它。中列出的 UIView 上的 UIConstraintBasedLayoutDebugging 类别中的方法也可能会有所帮助。

在此处输入图片说明

约束是自动生成的。
我该如何解决这个问题?