按钮未点击

时间:2020-08-29 01:45:41

标签: swift xcode swiftui

使用SwiftUI。由于某些非常奇怪的原因,此按钮不可单击(它出现但不执行其动作任务)。当我将Button放在HStack外面时,它突然工作了。我是愚蠢的还是它的错误。谢谢!

    ZStack{
        Image("Background")
            .resizable()
            .edgesIgnoringSafeArea([.top, .bottom])
        
        VStack{
            HStack{
                Text("Dari Learner")
                .font(.largeTitle)
                .foregroundColor(Color.white)
                .padding(.top, 50)
                .padding(.leading, 90)
            
            
            Button(action: {
                print("Button Tapped")
                self.viewModel.createQuiz()
            }) {
                        Text("Next")
                            .background(Color.green.opacity(0.5))
                            .cornerRadius(25)
                            .opacity(self.dim ? 1 : 0)
                        
                    .transition(.scale)
                        .animation(.easeInOut(duration: 1.5))
            }// !disabled because this is also used for the answerbubbles
            }
            
            ZStack{
                AnswerBubble(fillColor: Color.black, isChosen: false)
                Text(viewModel.getActualAnswer().word.DariWord)
            }
            
            
            Grid(viewModel.answers) { answer in
                
                QuizView(answer: answer,
                    fillColor: self.colorFor(answer: answer, correctAnswer: self.viewModel.getActualAnswer())).onTapGesture {
            
                    self.tappedAnswers.append(answer)
                        
                    if self.viewModel.chooseAnswer(answer: answer){
                        self.dim.toggle()
                        self.disabled.toggle()
                    }
                }
                .animation(.easeInOut(duration: 1.0))
                .disabled(self.disabled)
            }
        }
        .edgesIgnoringSafeArea([.top])
    }.onDisappear{
        self.viewModel.createQuiz()
    }

0 个答案:

没有答案