Sober come back again in this exercise we're going to use a combination of a wire rotation just to recognize
that I you I pinched the riser to rotate on a scale a wide view.
So I'm going to pause the video for a few seconds.
You give it a shot on your own.
And then if you wanted to can follow along with my solution as well.
OK.
So I'm going to go to Mexico now and I'm going to start a new project called Just shows and transform
because that's essentially what it is a transformation.
And my storyboard I'm going to make myself a you I view which I'm going to make it to be 256 on 256.
As always this part of the work I'm actually going to go through them quite quickly because I know that
you guys know exactly how to do it you don't really need my help with it.
So this is the red box and that's all I need in my interface field.
Now my actual programming is swift.
I need to have two gestures so I'm going to say let's call it wrote just that's going to be a rotation
just for recognizer.
I'm going to have a vowel let's call it scaler just it's going to be a u i pinch gesture recognizer.
Now in my view a lot.
I'm going to go ahead and essentially initialize both of them.
There is really practically no difference between doing both of these in the interface there or if you
want to do it here in the court are would both work exactly identically with on one end within the code
so that we get to see it here as well.
So it just becomes you like rotation just for recognizer of yourself.
And we need to have an action with a selector.
So I'm going to say that action is called rote action or something to that effect.
And then I'm going to have to say I have a scale gesture which is going to be a I pinched gesture recognizer
with Target's self and action being a selector Salek the center of a scale action.
So now I need to have both of these actions.
So I'm going to say a function rotation action and it has an arc.
It doesn't actually need to have an argument so there isn't.
I thought first I can have the argument is because I wanted to get the gesture but the gestures already
have a kind of a global variable.
So I don't need to have an argument here.
So I have a rotation action and I have the other one which is called the scalar action and that's that
one.
Finally in my view that note I'm going to have to say we should add both of these to our red box.
So when I say red box dot I'll just show recognizer Roths gesture and the red box thought I just recognize
the scale gesture.
And finally this is giving me an error saying that your selector methods are not exposed as objective
see.
So I'm going to have to do two.
This is something we have seen many times before.
The part of swift for I'm guessing and the new versions this will be this will be gone.
So that's about that.
My view of the lot of both of the gestures are initialized underboss applied to the red box.
And now we have to actually do teams with them in their functions.
So I'm going to fold this one and I'm going to go to my rotation action and say in the rotation action
red box dot transforms becomes red box start transformed those rotated.
And the value of they want rotate is the rotation of the rotation gesture.
I'm going to say let's new wrote to be rotations just sheer dot rotation and I'm going up right.
Got C.G. fruit in here.
Now I'm working on this application.
Even though I know it is not going to work because I want to show you something that is a very important
concept something that is going to go wrong now and we have to fix it once it loads.
We should see some really unexpected results so if I try to do this you can see that it's rotating with
really unexpected values.
And the reason for it is this the value of the rotation just is constantly adding to itself.
So if I'm rotating these and try to only look at the two tops that I have on the screen you find rotate
this say 90 degrees which is like this.
That's going to be 90 degrees that is being recorded into my rotation just share and then when I wrote
it down under 90 degrees the first 90 degrees and the second one are getting our data to each other.
So it's kind of adding the values one is there by the time itself and to remedy that well you're going
to do it if you're going to reset this value to zero every time we make a rotation so I'm going to come
in here and say well we got the value we rotated the red box.
Now you have to reset to zero.
So let's go ahead and check it out again.
What I read on the application and this time in every roll cycle we're going to add a little rotation
to the red box.
But then it's going to zero itself out and if we rotate the way we wanted rotate so what station is
working the way you want it to rotate.
So that's one thing that you have to keep in mind that the amount of rotation is actually being constantly
added tweets if we will face a very similar situation with this scale.
So in this case I'm going to say let me show a scale that's going to be a scale just sheer scale and
this value is actually constantly multiplying itself by the previous one because it's a ratio so the
ratio is based on the default value of one.
And now he's saying well it's now 1.1 times of the previous one.
And then when it gets another one it's not going to multiply by the default one is going to multiply
by the previous one which is not something we want.
So I'm going to say Redbox not transform transform is going to be a red box not transform the scale
the boy.
And the value we want is the newest scale for both x and y.
Newer scale but once I'm done with that I'm going to say a scale just sheer scale defaulted back to
one.
Don't keep the current value in it.
So I'm going to run this again.
And now we can scale properly and we can also rotate properly sometimes that the gesture doesn't really
recognize which one you're trying to do with a rotation you're attempting or it is the escape tempting
but that's perfectly fine.
And yeah that's that's why I have to tell you about these two guys.
There is another thing that you might want to keep an eye on.
And that's the state of a gesture recognizer are the states are very similar to the same states that
we have for touches.
They are begin are unchanged.
And so sometimes you can actually do things.
It just shows doors and or does begin.
And you can obviously read up on all of those on on the manual under header files as well.
So that was it made this exercise and I would you in the next lesson.