UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Project 6 part 3 - opacity of a button changed automatically when it is tapped

Forums > 100 Days of SwiftUI

Hi Everyone,

i do the project 6 part 3 challenge when you must go to the project GuessTheFlag and append some animation according to the answer. No problem for this. But i noticed something that prevents me from having a full opacity on the flag of the correct answer. By default (without any code for this), when a button is tapped, it's opacity change to become something like 0.7... When i force to have 1.0 (full opacity), it's the same (i can't overidde this native behavior). Any idea ?

2      

Try adding the .rotation... after the closing curly bracket of the button image view as follows __

    ForEach(0 ..< 3) { number in
        Button(action: {
        if number == self.correctAnswer {
            self.flagTapped(number)
            self.userTapped = number

            withAnimation {
                self.animationAmount += 360
            }
        }
        else {
            self.flagTapped(number)
            self.userTapped = number
        }

        }) {
        Image(self.countries[number])
            .renderingMode(.original)
            .imageModifier()

        }.rotation3DEffect(.degrees(self.animationAmount), axis: (x: 0, y: number == self.userTapped ? 1 : 0 , z: 0))

    }

4      

The solution above worked for me. Thank you!

However, I don't understand why it worked. If .rotation3DEffect is a modifier of Image(), then why does that prevent opacity from reseting to 1.0?

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.