问题描述
我开始使用自定义容器,但一直在尝试发送 @State var。示例代码:
struct ZoomCardView<Content: View>: View {
let contentDefault: ((Binding<Bool>)) -> Content
let contentZoomed: (Binding<Bool>) -> Content
init(@viewbuilder defaultContent: @escaping (Binding<Bool>) -> Content,@viewbuilder zoomed: @escaping (Binding<Bool>) -> Content) {
self.contentDefault = defaultContent
self.contentZoomed = zoomed
}
@State private var isShowing: Bool = false
var body: some View {
HStack {
if isShowing {
self.contentZoomed($isShowing)
.transition(.scale(scale: 0,anchor: .center))
} else {
self.contentDefault($isShowing)
.transition(.scale(scale: 0,anchor: .center))
}
}
}
}
这个想法是调用站点将呈现内容并提供切换 isShowing
变量的机制。其基本原理是允许调用站点决定哪个手势或 UI 元素控制切换:
struct ContentView: View {
var body: some View {
ZoomCardView { isShowing in
Button(action: {
isShowing.toggle() <---- *** Error (see below)
},label: {
Text("Open")
})
} zoomed: { isShowing in
Button(action: {
isShowing.toggle() <---- *** Error (see below)
},label: {
Text("Zoomed")
})
}
.frame(width: 300,height: 300)
.cornerRadius(15)
.shadow(radius: 5)
}
}
问题:我在上面的两行 Cannot call value of non-function type 'Binding<() -> ()>
中得到一个 isShowing.toggle()
。我不知道为什么。有什么想法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)