【发布时间】:2020-08-26 23:11:57
【问题描述】:
我正在制作一个语言应用程序,并希望用户点击它后正确答案显示为绿色,但我正在努力做到这一点。
这是我想要实现此行为的代码部分。
Grid(viewModel.answers) { answer in
//how can i change the ui of quizView(answer) that is being tapped inside the closure
quizView(answer: answer).onTapGesture {
if self.viewModel.chooseAnswer(answer: answer){
self.dim.toggle()
self.disabled.toggle()
print("a")
}
}
.opacity(self.dim ? 0.4 : 1.0)
.animation(.easeInOut(duration: 1.0))
.disabled(self.disabled)
}
}
.edgesIgnoringSafeArea([.top])
}
}}
struct quizView: View {
var answer: LearnModel.Answer
var body: some View{
GeometryReader { geometry in
ZStack{
answerBubble
Text(self.answer.word.EnglishWord)
.multilineTextAlignment(.center)
.foregroundColor(Color.white)
}
}
}}
var answerBubble: some View {
RoundedRectangle(cornerRadius: 20)
.fill(Color.black)
.shadow(color: Color.black, radius: 20, y: 5)
.opacity(0.2)
.padding()
}
Grid(viewModel.answers) - 为答案气泡创建 Grid 和 Gridlayout。
界面截图
【问题讨论】: