【发布时间】:2021-08-21 16:51:01
【问题描述】:
下面的 swift 代码负责根据视图中定义的状态值显示视图,如果值为 true,则打印打印,如果不是 true,则不显示任何内容,现在定义状态的值 (Gotocropview) 是作为绑定传递给另一个视图,然后更改为@Bindign,如果我在 ContentView 视图中注释该行,则编译代码,而如果该行未注释,则代码将按照 contentview 中显示的代码执行,它是产生错误:编译器无法在合理的时间内对该表达式进行类型检查;尝试将表达式分解为不同的子表达式,这是因为什么?
注释行:
/* else if(Gotocropview==true){
print("Crop view è true")
}*/
Swift 代码:
struct ContentView: View {
@State var Gotocamera:Bool = false
@State var Gotoeditcamera:Bool = false
@State var Gotocropview:Bool=false
@Environment(\.presentationMode) var presentationMode
var body: some View {
ZStack {
if (!Gotocamera && !Gotoeditcamera && !Gotocropview) {
Color(#colorLiteral(red: 0.9682741117, green: 0.9682741117, blue: 0.9682741117, alpha: 1)).edgesIgnoringSafeArea(.all)
VStack {
Header()
Search()
.padding(.top, 10)
Buttons(Gotoeditcamera: $Gotoeditcamera,Gotocropview: $Gotocropview)
.padding(.vertical, 20)
Cards()
.padding(.top, 20)
if(Support.getDevice() == DeviceType.ipad) {
Tabbar(Gotocamera: $Gotocamera)
.padding(.top, 200)
}
else{
if(Device.IS_IPHONE_XS){
Tabbar(Gotocamera: $Gotocamera)
.offset(y: 20)
}
else{
Tabbar(Gotocamera: $Gotocamera)
.offset(y: 60) }
}
}
}
else if(Gotocamera==true) {
CameraView()
}
else if(Gotoeditcamera==true){
ChangeEffect()
}
else if(Gotocropview==true){
print("Crop view è true")
}
}
}
}
struct Buttons: View {
@Binding var Gotoeditcamera:Bool
@Binding var Gotocropview:Bool
...
}
【问题讨论】: