NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

Flag Opacity animation - Day 34

Forums > 100 Days of SwiftUI

Hi! I'm struggling to make the other two buttons fade out to 25% opacity. I tried to keep the opacity for the correctAnswer at 1. Then adjust the opacity of all the flags to 0.75. I did this because it thought the correctAnswerOpacity = 1 might override the opacity(0.75). But unfortunately all it did was make the non correct answers invisible! Any chance someone know why this is happening? why/if my logic is flawed? and what should be done? Any help would be greatly appreciated!

         @State private var correctAnswerOpacity = 1.0
    @State private var otherFlagsOpacity = 1.0

    // Some other code

            ForEach(0 ..< 3) { number in
                Button(action: {

                    withAnimation() { self.flagTapped(number)
                        if number == correctAnswer {
                            animationAmount += 360
                            correctAnswerOpacity = 1                            
                { Image(self.countries[number]).renderingMode(.original).clipShape(Capsule()).overlay(Capsule().stroke(, lineWidth: 1)).shadow(color: .black, radius: 2)
                .rotation3DEffect(.degrees((number == correctAnswer) ? animationAmount : 0), axis: (x: 0, y: 1 , z: 0))
                .opacity((number == correctAnswer) ? opacityAmount : 0)


Hacking with Swift is sponsored by Fernando Olivares

SPONSORED Would you describe yourself as knowledgeable, but struggling when you have to come up with your own code? Fernando Olivares has a new book containing iOS rules you can immediately apply to your coding habits to see dramatic improvements, while also teaching applied programming fundamentals seen in refactored code from published apps.

Try the book!

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

Reply to this topic…

You need to create an account or log in to reply.

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.