我有三个按钮,但我希​​望其中一个可以旋转

我正在为这个问题苦苦挣扎的两天。我正在使用HackingWithSwift的#100DaysOfSwift学习Swiftui。到一天结束时,我要求进行上一个项目并进行编辑。

该应用程序只需将三个Button放入VStack中,并要求用户猜测正确的标志。

VStack{

                ForEach(0..<3){ number in
                        Button(action:{
                            self.flagTapped(number)
                        }){
                            FlagImage(numberOfTheFlag: self.countries[number])
                        }.rotation3DEffect(.degrees(self.rotation), axis: (x: 0, y: 1, z: 0))
                }
                // more code...

函数flagTapped()是:

func flagTapped (_ number: Int) {
     debugPrint(rotation)

    if number == correctAnswer {
        scoreTitle = "Correct! Great job."
        score += 1
        withAnimation{
            self.rotation += 360
        }
    } else {
        withAnimation {
            // wrong animation
        }
        wrongFlag = number
        scoreTitle = "Wrong! That's the flag of \(countries[number])"
    }
    showingScore = true
}

问题是:所有按钮都同时旋转。

THE PROBLEM

我该如何解决?

谢谢大家。