Now that you know how to use touch events it's time to move into gestures.
Just essentially a way of combining these different touches.
And someone has taken the trouble of writing the code for us and we can simply use those.
Let's go ahead into sports.
I'm going to start a new application called gestures of
and if you look through the storyboard and you will notice that there are a variety of gestures in here.
We have gestures such as tap pinch gesture or rotation gesture or humanize a swipe gesture he a prime
a screen edge and long press as well as a custom one that you can write different things in it on your
own.
So for now I'm just going to go ahead a top just show recognizer which is pretty similar to having it
touches and dead.
And I'm going to go ahead into my assistant to say when my type gets three get do this a new action.
That action is my gesture action so that's about that.
Going into our view.
I don't mean you to do it at least not for now.
And the first thing I want to do is I want to get to know which gesture has shown up here so I'm going
to say you let And I'm going to call this one.
My tap gesture is going to be send you my top just should recognize if my sender is they you are going
to answer.
Then I have to I I have an error and the error is oh I made this one and unforced and dropped one.
So I have to actually make it an optional phone because we don't know if sender is they you want just
recognize.
Let me share the error once again.
Let me read exactly the error that gave me.
It's saying that for conditional binding must have an optional type so I'm going to say it is an optional
type.
OK so if that is the case then just say print and I'm going to train that before I run it.
I want to show you that you just showed those Heather fine just to get a sense of what it has.
It has number of caps required.
That's something we can set.
And the number of the touches that is required.
So I think both of them are also here.
So we could actually go in here and say a number of the types on the number of the touches.
That's right.
This is obviously the simplest of all the possible of gestures in here.
I'm going to load up my console so I can see what I'm doing.
And every time we type it says papped.
So I think the final scene here let's go ahead and do something a little bit more elaborate.
How about a going here.
It's my tap gesture and I'm going to go to my library and look for a pen just gesture.
So my pinch just you recognize has a scale so it can tell me how much I scale something.
You know one of your upcoming lessons I would actually write this down myself when you say you can understand
how you would go ahead to scale something using C.G. transform.
But for now we going to read the value from the scale they have in your gesture and I said I'm going
to go to View Controller get the connection and say that action my gesture action I'm going to connect
it to this outlet.
The pinched gesture victimiser.
Let's go back to my view controller.
I'm going to have to change all of this of course.
I'm going to say if I let my pinch just is the send as you or I pinched just show recognizer.
So now we have a pinch just should get nicer.
Now we can get things such as a scale we can say the scale is and the value of it is might pinch that
escape.
And this is essentially a ratio between the current distance between the two taps and the previous one
and that's about that it's giving me some warning which is I don't think that's a real thing.
What does it say replace that.
Blah blah blah blah know the value has been used I think this is one of those things that it gets a
start.
Next quote because my type just doesn't even exist anymore.
Let me clean my.
It's gone.
And if you're wondering you clean the code using Come on shift then k.
And that is hishe clean.
Bill Yes it cleans everything up.
OK.
So let's go ahead and run this now in my simulator.
Hopefully we should be able to see a scale happening.
So I'm going to go in.
Yeah.
It's easy to see it gives me a scale which is essentially a ratio between the previous stands and the
current one.
If I clean this now on top in yet I move a little bit it says 1.00 some really a small number.
And if I go further it becomes a larger one and a smaller one the smaller one.
Now let me show you another few types of gestures.
One of them is a tap.
Just very used to treat your a Segway and let's see how you do that.
And when I go in here and say have another you or you or another you have your controller rather and
this you wave your controller I'm going to say it is a different background color.
So we know it's distinct and then I'm going to go in yeah and a tap just should recognize the G is here.
I want to cause a sync between these two.
You know in a normal situation you could simply do this.
You could go ahead of your controller even if your gesture happens.
Assuming this is the gesture you want then you would say yes start performs say grace so on and so forth.
Things that you have done before but now I want to do it in the visual interface.
So here I'm going to go ahead and say Give me from this trap just sheriff Wickenheiser to the pink controller.
Make sure.
So essentially it becomes an input here in the trigger segue.
So you could actually add them right here in the interface builder if you wanted to do a creature on
this app even though you only know what is going to happen.
The moment we tap we should essentially see a navigation to the other side which we go.
Perfect that happens.
Finally let me show you another kind of gesture which is kind of an important one and that is a UI rotation
just should recognize.
So this one location.
So a rotation recognizer works like everybody else and has a rotation value.
So if I go ahead in here into my view controller and say in the connections I have my gesture action
connected to the rotation that's there I can go out of your control and say my roll my rotation or rotation
just show recognizer is a your eye rotation just should recognize that I can say rotation is the value
of the rotation dot rotation.
And the reason I want to show you this is because the values that we will get in it is not in degrees.
So if I begin rotating very good values that are of the type float if you want to convert this rotation
into a degree value you could simply say Let my degree or that degree rotation harmers my rotation just
dot rotation I'm going to multiply that one hundred and eighty and I'm going it's divided by pi.
The only thing you have to keep in mind is that this fight is from the C-g flawed values.
So it's going to be C.G. float dot PI and that's about that.
That's the degree value of it up something I would recommend you doing is that you actually add an extension
to your floating point NCG float.
So I would think that going here and say extension C.G. fluid.
I would add something to that.
And then I would say another extension extension would be for binary integers with that other value
in there.
But I'll leave this for later when we do more exercises.
For now when we get the rotation value we can simply go ahead and convert it manually every time.
Let me run this now and it should give us this time to rotation in a degree mode.
So if I go in here and I rotate this much it was 20 30 40 60 90 degrees one hundred and eighty degrees.
Numbers are a little bit more more familiar to our minds.
I personally don't know.
I mean I know how radians work but I can't really imagine the radium values as easily.
So that's about that.
We talked about tap just shows a scale of just sheer Penge gesture and rotation just for a number of
other gestures in here I suggest that you try them on your own such as a slight gesture and a pine and
just short of a long press just for each of them has their own set of attributes.
They do things such as a swipe just shake can have a direction in which you can swipe and causes something
to happen or a long press gesture has a certain length that you have to press a minimum duration that
you have to press before it is being triggered.
And yet that's about just shows on you in the next.