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

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(Color.black, 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)
                .opacity(0.75)

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.