|
So the challenge is: **Go back to the Guess the Flag project and add some animation: When you tap the correct flag, make it spin around 360 degrees on the Y axis. I know that I need to make a conditional animation... so I tried using a ternary operator.. the problem is.. I've never seen ternary operators work with methods that take more than one argument... for example I know that .background(someBool ? .red : .blue) works.. but how about: .rotation3DEffect(someBool ?. .degrees(someCFGValue), axis: x: 0, y: 0, z: 0 : .degrees.............. a so after some tweaking I got the ternary operator to work, but it rotates all 3 buttons.. not just the correct one. So what do you guys suggest? Here is a snapshot of what I have now (Cant upload a photo like i thought) |
|
Instead of posting an image, post your code between backticks
|
|
|
|
I've been banging my head against this one for a while, and I manage to get the individual buttons to rotate individually, but couldn't get the opacity to work with it... yet. It took a while, but it dawned on me that we are basically attaching the animation to the I then realized we are using the same variable to update the animation. So I did the sensible thing and created 3 different variables to be used for each separate button like so:
and for the buttons here's the change necessary:
1- notice that I hard-coded the buttons numbers. we know the range we use in the ForEach are the numbers: 0, 1, 2. So make sure to update accordingly for each button. 2- notice how we end up using a specifc amount that relates to this button only. Which only ever gets updated at the right time. 3- The animation certainly needs work. It's rough and continues after the game updates. I know. Now the challenge of figuring out the opacity change. and then the wrong guess scenario. |
|
@MarcusKay You didn't need to make three separate animationAmounts, you could have added a ternary expression in the degrees parameter:
I changed the axis of rotation for my own benefit, I like it better lol. |
|
@Jargen89 Excuse me while I go slap my face........ I went entirely and totally blind to the fact that we had This is gonna crack me up for a while. It's always the smallest things. And yea, I'll fool around with the animation.... and some of the other approaches I've been reading... |
|
@MarcusKay It happens to the best of us, no worries. |
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.