在整个网络上搜索这个确切的错误并没有发现任何结果。我只想创建视图的多个副本,首尾相连,以创建类似于标尺的水平布局。在运行时,它将创建足够的段来覆盖特定的长度。
但是,我收到上述错误。将
id:\.self
添加到 forEach
并不能解决问题。
import SwiftUI
struct MediaPositionView: View
{
var body: some View
{
HStack(spacing: 0)
{
ForEach(0..<10)
{ index in
songSegment(segIndex: index) // Static method 'buildExpression' requires that 'Content' conform to 'MapContent'
}
}
}
@ViewBuilder func songSegment(segIndex: Int) -> any View
{
ZStack
{
Color.blue
.frame(width: 50, height: 50)
Path
{ path in
path.move(to: CGPoint(x: 5, y: 25))
path.addLine(to: CGPoint(x: 5, y: 50))
}
}
}
}
函数
songSegment
需要返回some View
,而不是any View
:
func songSegment(segIndex: Int) -> some View