SwiftUIList将自动突出显示点击的行,前提是内部有一个 NavigationLink。
由于我使用嵌入在 UIKit 中的 SwiftUI via UIHostingController,我使用 a 处理导航UINavigationController,所以我不想使用NavigationLink.
但是,我需要在点击时突出显示列表行,这在使用时不存在.onTapGesture
我怎样才能做到这一点?
这是一个例子:
List {
Section(header: Text("Section header text")) {
HStack { // A row in the list
Image(systemName: "circle")
VStack(alignment: .leading) {
Text("profile name")
// Sub label
Text("Description")
.foregroundColor(.secondary)
.font(.system(size: 12))
}
Spacer()
}
.contentShape(Rectangle())
.onTapGesture { // Detect tap on the row
Print("Perform action here...")
// THE TAP IS NOT ANIMATED BECAUSE THERE IS NO NAVIGATION LINK HERE.
}
} …Run Code Online (Sandbox Code Playgroud) 这个问题听起来可能很傻,但我花了很多时间尝试却没有弄清楚。
我的数据代表一段时间内的车辆速度,粒度约为秒。因此有很多数据。我想自定义 X 轴(时间),使其仅显示每分钟的标签,或者更好的是每 30 秒显示标签。
这是到目前为止我的代码(正确显示图表,但 X 轴无法工作/显示):
Chart {
ForEach(orderedLocations) { item in
LineMark(x: .value("Date", "\(item.timestamp!)"),
y: .value("Speed", item.groundSpeed),
series: .value("Ground Speed", "A"))
.interpolationMethod(.catmullRom)
.foregroundStyle(.blue)
AreaMark(x: .value("Date", "\(item.timestamp!)"),
y: .value("Speed", item.groundSpeed),
series: .value("Speed", "A"))
}
}
.chartXAxis {
AxisMarks(values: .automatic(minimumStride: 60)) { date in
AxisValueLabel(format: .dateTime.minute())
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题?