使用@Namespace进行.matchedGeometryEffect的自定义初始化

问题描述

我正在尝试将具有@Namespace的{​​{1}}属性的自定义View结构传递给父View。

由于父母将提供.matchedGeometryEffect,所以我使用的是自定义Namespace

当我使用类似于init自定义初始化的语法时,Xcode会在初始化自定义View时强制我使用包装器。反过来会杀死我的@Binding

.matchedGeometryEffect

似乎有效的方法是使用struct MyView<Content: View>: View { @Binding var matched: Bool @Namespace var nspace let content: Content init(matched: Binding<Bool>,nspace: Namespace,@ViewBuilder content: @escaping () -> Content ) { self._matched = matched self._nspace = nspace self.content = content() } var body: some View { ... } } 而不是var nspace: Namespace.ID,然后:

@Namespace var nspace

这会在其他地方引起麻烦吗?有更好的方法吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)