|
Howdy, We have been stuck on getting our animation to animate when/where we want & have spent approximately 18 hours trying to complete this challenge. We know we have dedicated this much time to this as we stream on twitch & have all of the video of our struggle. First part of our code where we believe the problem is: This method is checking to see if we pressed the correct button to win & my thought process was/is this should trigger our animation.
This is our code for creating our buttons.
What is happeing is our Animation (spinning the correct button/image) is not happening until we call our askQuestion method (below) and then it spins the flag in the New Round (with the new flags) & also the button/flag of the new correct answer...hope that makes sense.
I believe the above code is where this is happening or rather NOT happeing, however I have provided the entire code below if you are so inclined. In any case, thank you for any guideance you might see your way fit to give. Baron https://www.twitch.tv/baron_blackbird
|
|
It might be due to the fact that you don't seem to have a "state" change.
You have declared You could potentially change your spinToWin function to return a Double.
and then when you set degrees you change it to:
You essentially need to tell Swift something changed for it to know that it has to do some update. Which is why, when you actually go to the next question, a state being monitored has changed, and the commands are executed. At least that's my understanding of what's going on. Hope that works/helps! |
|
Howdy, Thank you so much for taking the time to review our code & provide a suggestion. While it didn't work out as intended, it did get us a step closer; plus like you, I was under the impression an @State needed to be modified in order for our View to update, however I was not observing this behavior but you have reaffired my belief in this functionality of SwiftUI. Your solution has trigged a "Modfying state during view update, this will cause undefined behavior." warning. Again, very much appreciate the help. Baron |
|
I'll check the code later and compare to mine a bit, but maybe you can find some answer in another post about this: https://www.hackingwithswift.com/forums/100-days-of-swiftui/day-34-conditional-animation/3824 Hope that helps in the meatime. |
|
I copied your code into a new project to test things out and see where the differences were. (the answer was in the link). Here goes: 1- 2- You can keep
3- inside the action of our buttons we need to check if we should rotate. I used your
That's before or after the print section.
I would recommend changing the name to 4- In 5- in 6- And finally, we set the rotation animation according to these results like so:
When I tested the above it worked fine. I hope someone can explain why adding Hope that helps! |
|
Howdy, I will go over the link on my next stream (I do all my SwiftUI learning live) & thank you so much for the above...I thought I took at all of the What I can tell you is two flags were rotating, because it was rotating the one flag for the correctAnswer & then rotating the 2nd flag for the new correctAnswer for the next round...now, if the new correctAnswer (button 0, 1 or 2) was the same correctAnswer as the last round it wouldn't rotate depending on if you chose the ocrrect answer or wrong answer. I didn't figure that out until I was using a few print statements I deleted before posting the code. A few of the variables were left over from the many previous attempts to solve this issue. As I told my chat yesterday late in the program "Even if MarcusKay didn't get us over this hump, they took us down a new path towards a possible answer & even if that path didn't work out they reaffirmed our belief an I can't wait to give this a go! Big Fan, Baron |
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.