|
I originally tried this:
That doesn't work. I am not sure why. I got Paul's solution to work, but the flag rotates BACKWARDS when the alert is dismissed. I was puzzled by that, but eventually realized that SwiftUI does not know that .degrees(360) == degrees(0) |
|
Hey Now! You're not sure why your original code doesn't work? View FactoryThink of
In your code, it will create a view for each integer, 0, 1 and 2. What view will it create? ButtonsYour view factory will create three
Button DecorationYou've added two decorators to make your buttons look nice! For the most part, we can ignore these to focus on your animation question problem.
Planning AnimationGrab a pencil and a sheet of paper. Draw three flags in a column: Germany, Ireland, and France. Right next to the colum of flags, draw another column labeled "After" and draw the same three flags. Let's assume that the third flag, France, is the correct answer. So your Swift will update any view whenever one of its Consequently, we do NOT want to change any So on your sheet of paper, write down a variable named Write the number 0 in column 1 for France's flag, but change it to 360 for column 2. Views are redrawn when their How to signal a change?Now the question becomes, How do you change the Notice when each The other two flags are NOT redrawn because their @State vars did not change.
Debugging HintTo see the animation in slow motion in the simulator, tap the option Original Code
|
|
|
|
How did you solve the .opacity one? I ended up adding an additional @State variable that
whereas opacityV starts as 1.0, but once you press the button changes to 0.5 and with the reset button goes back to 1.0 This works but I am curious if there is a simpler solution... |
|
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
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.