我想制作一个列表视图,可以拖动其中的内容进行重新排序并点击以获取详细信息。但是,当我在内容视图中添加 onTapGesture() 操作时,onMove() 操作停止工作。
示例代码:
import SwiftUI
struct TestTapAndMove: View {
@State private var users = ["Paul", "Taylor", "Adele"]
var body: some View {
List {
ForEach(users, id: \.self) { user in
VStack {
Text("user: \(user)").font(.headline)
Divider()
}.background(Color.gray)
// The TapGesture will result in onMove action not working.
.onTapGesture(perform: {
print("tap!")
})
}
.onMove(perform: move)
}
}
func move(from source: IndexSet, to destination: Int) {
print("onMove!")
users.move(fromOffsets: source, toOffset: destination)
}
}
Run Code Online (Sandbox Code Playgroud)
是否有任何解决方案可以使点击和移动动作协同工作?