【发布时间】:2020-12-18 02:18:14
【问题描述】:
目前,我有一个显示所有图标案例的 foreach 循环。我想隐藏 case none 因为我的 EffectIcon 视图需要一个选定的案例。 父视图:
enum Icons: String,CaseIterable, Hashable {
case overlayText = "Text"
case image = "Image"
case rotate = "Rotate"
...
case none
}
struct EffectPanel: View {
@State var currentIconSelected: Icons = .none
@State var listIcons = [Bool](repeating: false, count: Icons.allCases.count)
var body: some View {
VStack {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 10) {
ForEach(0..<listIcons.count, id: \.self) { i in
EffectIcon(icon: Icons(rawValue: Icons.allCases[i].rawValue)!, currentIconSelected: $currentIconSelected)
}
}
.background(Color.black)
}
}
}
}
【问题讨论】: