TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your 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.