如何解决使用@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
这会在其他地方引起麻烦吗?有更好的方法吗?
解决方法
这会在其他地方引起麻烦吗?有更好的方法吗?
这并不坏/更好,这是唯一正确的方法。让我们看一下API:
Sub CopyPaste()
Dim lastrow As Integer,erow As Long,sheet1 As Worksheet,sheet2 As Worksheet
Set sheet1 = Worksheets("Sheet1")
Set sheet2 = Worksheets("Sheet2")
lastrow = sheet1.Cells(Rows.Count,1).End(xlUp).Row
For i = 2 To lastrow
erow = sheet2.Cells(Rows.Count,2).End(xlUp).Offset(1,0).Row
sheet2.Cells(erow,2) = sheet1.Cells(i,3)
sheet2.Cells(erow,3) = sheet1.Cells(i,4)
sheet2.Cells(erow,4) = sheet1.Cells(i,9)
Next i
End Sub
是用于标识匹配效果的名称空间的值
Namespace.ID
并且可以看到
/// A dynamic property type that allows access to a namespace defined
/// by the persistent identity of the object containing the property
/// (e.g. a view).
@available(iOS 14.0,macOS 11.0,tvOS 14.0,watchOS 7.0,*)
@frozen @propertyWrapper public struct Namespace : DynamicProperty {
@inlinable public init()
public var wrappedValue: Namespace.ID { get } // << here !!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。