|
hi there, the exercise objective is to: tap the correct flag, make it spin around 360 degrees on the Y axis. so, am having trouble figuring out how to write the code in order to make the correct flag spin. The code worked successfully when I wrote it under ForEach, but that made all 3 flags spin, regardless of whether the answer was correct or not. Knowing that, I believed it necessary to write the code below the if clause in func flagTapped. This is where it went wrong, and I'm unsuccessful in resolving the errors. Appreciate any guidance...
|
|
|
|
Apologies for not including the full code https://github.com/taylorpad32/taylor-SwiftUI/blob/main/GuessTheFlag/GuessTheFlag/ContentView.swift or below....
|
|
I was just having the same issues you were. What I did was create a bool to track if the flag should be animating. Next, you can move the withAnimation into your buttons actions. And you can use conditionals inside the withAnimation code. Something like this:
Then you can move the .rotation3D call into the label portion of the button and make it a modifier for your image. You can also you conditionals in this as well. Something like this:
You can add the opacity modifier to the flag image as well with conditionals. I'm sure there are better ways to do it. And you can change the animating effect to suite your tastes. But hopefully that helps you out a bit. |
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.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.