swift - 如何在 MacOS 上滚动时修复 SwifyUI 列表的重影?
问题描述
我在透明背景ForEach
下使用SwiftUI
on ,它在滚动时显示重影,这是错误还是错误用法?我该如何解决?谢谢!MacOS
NSWindow
SwiftUI
代码在这里 https://github.com/someniceone/SwiftUIListGhosting
我的代码:
struct ScriptListRow: View {
var script: Script
var index: Int
var body: some View {
HStack {
Image(script.iconName)
.resizable()
.frame(width: 20, height: 20, alignment: .center)
Text(script.filename)
.foregroundColor(Color.white)
Spacer()
}
.padding(.horizontal, 5)
.padding(.vertical, 8)
}
}
struct ScriptList: View {
@State private var selectedId: Int?
let withIndex = scripts.enumerated().map({ $0 })
var body: some View {
ScrollView {
VStack(spacing: 0) {
ForEach(withIndex, id: \.element.id) { index, script in
ScriptListRow(script: script, index: index)
.background(selectedId == index ? Color.accentColor : (index % 2 == 1 ? Color.clear: Color(white: 0.1, opacity: 0.2)))
.onTapGesture(perform: {
selectedId = index
})
}
}
}
.frame(width: .infinity, height: 300, alignment: .top)
}
}
解决方案
推荐阅读
- docker - Docker 容器输出不会更新其标准输出的最后一行,而是垃圾邮件
- python - 从并行运行脚本更新值的最佳方法 - Python
- javascript - JavaScript 没有从“getElementById”获取值
- c# - Quartz.NET 三级架构С#
- python - 从另一个正在运行的python文件访问一个类实例/变量?
- angular - 带有 rxjs 的异步管道
- python - 为什么 Vim 用 +python3 编译时运行 python2?
- javascript - 需要一些关于如何查找由 JavaScript 生成的动态 DOM ID 的说明
- node.js - ejs 文件已加载但没有出现
- excel - 如何在两个拼写错误的字符串之间进行部分匹配