So never come again.
We use transformations.
You know I was for doing three things in particular.
One of them is translation.
The other one is rotation and the third one is a scaling an object.
Now transformations can be applied on almost any type of outlet and you can do any of these three particular
types of transformations on those outlets.
So let's have a quick look at how we do it in court.
I'm going to jump into excuse making your application.
I'm going to call it.
This is from Nation's
and as usual I'm going to go and have myself a great view.
I'm going to make a view which is going to be like that
and that I'm going to make a point because I want to be able to apply different types of transformations.
It's going to be set up by shrine's formation.
I'm going to go with a slightly different back on the caller.
Let's have the outlet as well as the action.
So the outlet is the red box and the action is I don't need to view that lot.
I'm going to say the option is here apply transform ish and that's all I have to do in the interface
builder so I'm going to jump back to our view that lot swift fine and in here for a month everything
a little bit better.
And the first piece of core they want to write is this I want to say when I pressed the I apply transformation
I want to move this object by let's say 100 pixels.
So it's going to be set red box which is the object that I have thought transform becomes a red box
that transform DOD translated by.
And I want it translated by let's say 100 and 0 on the Y.
So let's see what you have.
What we're doing is you're saying that the transform of red box that's like the pivot point of it.
For those of you come with the background of our computer graphics the pivot of it becomes the current
pivot plus 100 pixels on the X as simple as that.
So let's run that on my simulator.
We will see something that is actually important and that is let me actually show it to you and then
explain to you so here if I press apply it it jumps to the right and the things are interesting and
I want to show you is that if I press again it jumps another 100 simply because it's saying every time
I replace this transform with whatever is the transform and the hundred to it's so simply if we do multiple
you know runs of this action the object completely goes out of the screen.
Now we can do similarly the same thing for scale and rotation.
And then I actually do those say red marks that transform becomes very boxtops transformed not rotated
by now the rotation is a radiant value.
So as you can imagine a radian value is based on PI number.
So for that I would simply say give me CGU float float dot pi.
And that's three point one for one hundred and eighty degrees for a half circle.
And I would say let's divide that by four.
So now if I go in here every time I press we rotate 45 degrees as well as moving 100 pixels.
If we make this a little bit less so we can see it easier.
And if these numbers are difficult for you you can actually contradict them.
So you can simply say if I want to find what's the value of 45 degrees essentially I would take 45.
Divide it by one hundred and eighty and then want to play by 2.1 four.
Or if you want to do with a lot more scientifically you could simply say well flawed fish ship fruit
of Pi and then multiply it by the number that you are interested in 45 degrees divided by one hundred
and eighty and this would be a most accurate calculation of it that the machine automatically finds
the absolute value of pi up to a certain number of decimal places and then multiply it by that number.
Or if I were to be turtle it is for instance not before this game.
Let's just go ahead and say red box start transform becomes red monks transform dot scale the VI and
the scale has two different arguments.
This scale on the horizontal level X on the vertical I want someone to say undie x make it up 8 or 80
percent of its kind size and under Y make it maybe 1 point zero or five.
So let's see.
So every time I press that button up here we should rotate by 30 degrees.
We should move 20 pixels and we have to shrink on the X and it's slightly increase on the vine.
And that's kind of what we expected to see.
Now let me show you what would happen if we only applied a scale and when I explained to you why I want
you to see that so this time and we do the transformation we only apply the scale.
Part of the transformation on aardvarks and that's exactly what you were hoping to see to see that it
shrinks and the X becomes point eight times at times and increases by one point zero or five.
Now the reason the last time we saw some sort of rescue happening as if the shape of the rectangle was
changing simply because the transformation was rotated.
So the object wasn't the same people with anymore as it is here right now.
So let's look at that once again.
So we assume by default that the object has a veto on a height but when it rotates that actually changes.
Now our pivot is not the pivot that has an XT was the right of the screen and white was the top of the
screen.
If we try that again now if rotation that was there in the first attempt is being considered in the
transformation that happens this time.
And that's essentially why we get this askew type of type of transformation.
Now let's go back in you know I want to show you a few more things.
One of them is that all of these transforms are essentially subclasses of another class quad core graphics
aften transform sounds for.
And one of the things that you could do it would say red box that transform becomes C.G. aften transforms
that identity entity.
And that's essentially like your resetting your transformations.
So anytime you call the identity is going to push everything back to their default was based on what
the storyboard has generated or where the view was originally initialized.
So that's one thing to keep in mind and I'm going to actually comment all of these out now so that you
get
so that's commented out all.
So is this guy I don't want perfect and these guys will all play three types of transformations.
Now the first group of transformations would replace that transformation with a new one.
And as a result they were concatenating themselves.
Now I'm going to go ahead and say You've me in your transformation let's call it the rotation Trout's.
And that's going to be a C G F and transform and then transform station has different types.
And when I say rotation by an angle of let's say 1.2.
I don't know exactly what 1.2 years but you could easily calculate it.
I'm going to save 1.2.
Divided by two.
One for one place by one hundred and eighty.
It's about 65 68 degrees.
So rotation transformation and then I'm going to say say red box dot transform becomes rotation transformation.
And if you run this one now it rotates it by 68 or 70 degrees or whatever the number was for the fire
brigade.
Wartimes nothing is going to happen simply because the CGF untransformed is not adding on top of the
previous one.
It's simply saying make it this whatever disvalue is we can similarly have the same thing for scale
or for translations.
So let the scale rounds to become CEG and transform a scale by again is asking me for some values of
1.5.
One point one one point one.
And here's the thing you can only apply one of these guys to your the box that transform.
So my read books that transform either can be rotation trines or it can be scaled trons And if you want
to add them together I have to do what we call a concatenation.
So you have to say rotation transformation just concatenates scale translation.
And this is a process that you can continue for ever.
You can have hundreds of them being sequentially added together.
I like that you can end up having a combination of all the transformations being applied at once.
Perhaps not usually the case for what you want but there is a way for it.
Let's run this application once again.
Yet if I press apply we get a rotation and skate at the same time.
OK and so this was a quick introduction to applying transformations in the next few lessons we'll be
using them more often to do more advanced stuff and a combination of them with touch and gestures.
And I see.