我正在尝试做一个简单的事情matchedGeometryEffect,但它不起作用。我有一个Image具有固定框架的简单动画,我想将其动画化为Image占据整个屏幕的动画。这就是现在的样子,正如您所看到的,它的过渡并不顺利:
这是我的代码:
struct ContentView: View {
@State private var enlarged = false
@Namespace private var animation
var body: some View {
ZStack {
if (enlarged) {
Image("dunes")
.resizable()
.aspectRatio(contentMode: .fill)
.matchedGeometryEffect(id: "image", in: animation)
.ignoresSafeArea(.all, edges: .all)
} else {
Image("dunes")
.resizable()
.aspectRatio(contentMode: .fill)
.matchedGeometryEffect(id: "image", in: animation)
.frame(width: 300, height: 225)
}
}
.onTapGesture {
withAnimation {
enlarged.toggle()
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试reduce在数组上使用该函数:
var fields = ["gender", "name", "nickname"]
var stats = fields.reduce([String:String]()) { (res, field) -> [String:String] in
res[field] = json[field] ?? ""
return res
}
Run Code Online (Sandbox Code Playgroud)
它只是通过fields数组并将json对象的值赋给res.
对我来说似乎很简单,但编译器一直说:
错误:不能通过下标分配:'res'是'let'常量
在线上:
res[field] = json[field] ?? ""
Run Code Online (Sandbox Code Playgroud)
这对我没有任何意义,因为我从未指定res或stats作为let.
这是来自Github上的公共Eureka项目.我正在尝试理解源代码(和Swift泛型).我停留在这个片段的最后一行.最后一行在做什么?
open class Row<Cell: CellType>: RowOf<Cell.Value>, TypedRowType where Cell: BaseCell {
/// Responsible for creating the cell for this row.
public var cellProvider = CellProvider<Cell>()
/// The type of the cell associated to this row.
public let cellType: Cell.Type! = Cell.self //what is this line doing?
Run Code Online (Sandbox Code Playgroud)