我在滚动视图中添加了三个按钮,我想在用户单击按钮时获得效果-仅单击该按钮,而不单击每个按钮,因此隐藏的描述仅出现在单击的按钮上
和代码:
df1$Matches <- res
答案 0 :(得分:1)
这是一个解决方案。经过Xcode 11.4 / iOS 13.4的测试
struct WordCells: View {
@State private var toggleView: Int? = nil // << selection
var numberOfItems = Int.init()
var body: some View {
GeometryReader { geometry in
VStack(spacing: 40.0) {
ForEach(0..<self.numberOfItems) {item in
Button(action: {
withAnimation(.easeInOut(duration: 0.5)) {
if self.toggleView == item { // << here !!
self.toggleView = nil
} else {
self.toggleView = item
}
}
})
{
VStack {
HStack {
Text("Button Text")
.fontWeight(.bold)
.foregroundColor(.black)
.font(.callout)
Spacer()
Text("Description")
.fontWeight(.bold)
.foregroundColor(.gray)
.font(.callout)
}
if self.toggleView == item { // << selection !!
HiddenDescriptionView()
}
}
.frame(width: geometry.size.width/1.3)
}
.padding(23.0)
.background(Color.white)
}
.clipShape(RoundedRectangle(cornerRadius: 32))
.shadow(color: .gray, radius: 15)
}
}
}
}