|
Hi, I am looking for a pointer but not the solution. The challenge is "When you tap a flag, make it spin around 360 degrees on the Y axis." I can make them all spin, I can make any one of them spin but I cannot make the one that was tapped spin. The answer must be in the learning from day 32 & 33 so I'd be grateful if someone could tell me which of the learning topics I need to revisit to solve this challenge. Thank you for your help Regards Ian |
|
This challenge was a tough one for me. But I think the thing that helped me the most was realizing that I needed to create a variable to store which button was tapped to accomplish this. We aren't storing that information anywhere yet when the project is finished. But, we have no way of making sure that the animation is only applied to that button if we don't store that information at the time when it is tapped. |
|
|
Hi, I am slipping behind because I am refusing to move on until I understand how and why something works. The code below spins the pressed button and dims the other two, but I am not really sure why. I am not really sure why the pressed one spins but I'm doubly unsure why the other two always dim. Also, how do a return the opacity of the two that dimmed ready for the next press? Any simple explanation appreciated. Thank you for your help. Regards, Ian
|
|
Ian wants animations to come into focus!
KodachromeYou take great photos! Think about taking a photo of a distant bridge. Set your telephoto lens such that you have the most blurry image possible. Call that photo #1. Take another photo that is at the other end of the focus spectrum--every detail is sharp and crisp! This is photo #10,001. Now, think how many gentle nudges you'd have to give your telephoto lens to take 10,000 photos while ever-so-gradually bringing that bridge into sharp focus. THIS. This is how SwiftUI creates animations. First it looks at your Button view before you tap. In this state, the image is at full opacity, and is NOT rotating. Next you tap ONE image. The SwiftUI takes a photo of the BEFORE state. Then it takes a photo of the AFTER state. THEN, SwiftUI takes 10,000 photos whilst ever so gently changing the opacity of two untapped icons to 0.05. At the same time, it rotates the tapped button 360 degrees around the X-Axis. It makes these in between photos stretch over a four second period and streams them to your device so quickly you don't see the images change. This is how SwiftUI processes view animations.
ForEach = a View FactorySee -> It's a view factory! Another helpful article for you. When you're building a view and you use a In your solution, the Each time you interact with the app, you can bet that some part of your view is being redrawn. When you redraw your three It's convenient to CHANGE the It's convenient to CHANGE the |
|
It's a GameViewAlso, I changed your example from Why? I think it more accurately describes what the view wants to display. See -> Describe your View Please add your comments to that thread! |
|
Test your KnowledgeWhy is this code from your answer redundant?
|
|
I had a hard time completing this challenge. I think the biggest help I received was realizing I had to create a variable to store which button had been tapped. In the event that the project is completed, we have not yet stored that information anywhere. However, if we do not store that information when the button is tapped, we cannot guarantee that the animation will only be applied to that button. https://essentialsclothing.co/ |
|
I'm going to try to show the relevant parts of my code for this project, or at least, the way that I ended up modifying it. I don't remember how closely it matches what Paul asked us to do in the challenges for this project, so I'll give you an explanation of what it's doing with the animations first.
So basically, after any flag is tapped, you will end up with either 1 or 2 flags still showing. There will only be 1 if the tapped flag was the correct answer. But there will be 2 showing with the tapped flag being kind of faded if the tapped flag was not the correct answer. Hopefully that makes sense. I am going to use my code here rather than trying to explain yours because I think the structure of it is a little more clear, and the variable names might make some things a little more clear to you as well. But mostly because I think it will be easier for me to explain. Hopefully it doesn't just make you more confused in the end. Now, for the code... (I am of course excluding some functions and View body elements that aren't really relevant to the animation part)
First, I just want to point out this bit...
This is somewhat comparable to your Which, brings me to these...
Mainly, I just want you to notice how I've named them. These are the animation amounts that are going to be used for the tapped flag only. So, try not to get confused in thinking that these are the animation amounts for all of our buttons. It's easy to do that using a name like Also notice, I didn't actually make variables for the animation amounts of the untapped buttons. One reason is that I am never actually rotating the untapped buttons at all, so their rotation amount will always be 0.0. The opacity of an untapped button can change, however, and that's why I've created this function...
The reason I made it a function rather than a property is because I needed it to be able to take a parameter You'll see why I did it this way more clearly when you look at our
The interesting parts of this snippet are these lines...
Remember that these lines are inside of our The first line basically says "If this flag button that we are creating right now ends up being the The scond line basically says "If this flag button that we are creating right now ends up being the Our Side note: I'll tell you, it isn't actually 100% necessary that we used a function here, but the alternative was using very ugly and hard to read line of code like this...
So handling all that logic in a function makes things a lot cleaner and easier to read.
Now, lets not forget about the other interesting part of our So, what is the block of code that we used
As you can see, that will change our
But instead of making the changes instantaneously, Swift will make sure that they change incrementally, and that the changes are displayed in a frame by frame sort of way to the best of its ability. That just leave us with one other question that you asked. How do we make sure that these changes get reset when a new question is asked? Well, we have a function that takes care of asking the next question. So, that seems like a good place to handle resetting these values when the next question is asked...
(This function is called with the press of another button that I didn't show in the sample code here) Hopefully, all that helps to clear things up a little bit, rather than just confusing you further. But I tried my best! |
|
Thank you for all the help, especially to @Obelix for taking the time to comment on my code. I am still working through the replies but I think my main issue stems from my previous expereince of writing quite linear code, I was missing the fact that the the view will get redrawn with every change of state as they change and not just once at that point in the code. Thank you |
|
@Fly0strich, I've just been going through all your code and explanations, really helpful, thank you. |
|
Hi ! Im realy confused with this task. I only figured out how to spinn corrrect chosen flag but i cant make other flags dimm after button is pressed. In my code, wrong flags are dimmed from the begining :) Can you give me some hint here?
|
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
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.