【发布时间】:2020-02-23 01:07:37
【问题描述】:
我有一个显示数组项的水平滚动视图。
如何读取用户长按的滚动视图的索引。
使用 .onLongPressGesture {“要执行的操作”} 我如何读取要在我的函数中传递的索引以删除项目。
ScrollView(.horizontal, content: {
HStack(spacing: 100) {
ForEach(post, id: \.self){ item in
ZStack {
Rectangle().foregroundColor(.blue).frame(width: 190, height: 170, alignment: .center)
Text(item)
}.onTapGesture {
self.temp = item
}
.onLongPressGesture {
// find index
//perform delate at index
//pass the index to the function delate
self.delate(index: 0)
}
}
}
.padding(.leading, 10)
})
如果我手动编写索引 0,延迟工作正常,但我想传递用户长按的索引。 感谢您的帮助。
【问题讨论】:
标签: arrays swift xcode scrollview swiftui