1
00:00:01,200 --> 00:00:05,440
Now that you know how to use touch events it's time to move into gestures.

2
00:00:05,640 --> 00:00:09,800
Just essentially a way of combining these different touches.

3
00:00:09,900 --> 00:00:14,820
And someone has taken the trouble of writing the code for us and we can simply use those.

4
00:00:14,990 --> 00:00:16,840
Let's go ahead into sports.

5
00:00:16,950 --> 00:00:20,820
I'm going to start a new application called gestures of

6
00:00:24,610 --> 00:00:30,450
and if you look through the storyboard and you will notice that there are a variety of gestures in here.

7
00:00:30,610 --> 00:00:39,300
We have gestures such as tap pinch gesture or rotation gesture or humanize a swipe gesture he a prime

8
00:00:39,650 --> 00:00:45,880
a screen edge and long press as well as a custom one that you can write different things in it on your

9
00:00:45,880 --> 00:00:46,690
own.

10
00:00:46,690 --> 00:00:54,130
So for now I'm just going to go ahead a top just show recognizer which is pretty similar to having it

11
00:00:54,130 --> 00:00:55,730
touches and dead.

12
00:00:55,810 --> 00:01:05,920
And I'm going to go ahead into my assistant to say when my type gets three get do this a new action.

13
00:01:06,130 --> 00:01:13,780
That action is my gesture action so that's about that.

14
00:01:13,860 --> 00:01:15,780
Going into our view.

15
00:01:15,920 --> 00:01:19,270
I don't mean you to do it at least not for now.

16
00:01:19,790 --> 00:01:26,240
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

17
00:01:26,240 --> 00:01:30,800
to say you let And I'm going to call this one.

18
00:01:31,040 --> 00:01:44,840
My tap gesture is going to be send you my top just should recognize if my sender is they you are going

19
00:01:44,860 --> 00:01:45,870
to answer.

20
00:01:45,970 --> 00:01:54,810
Then I have to I I have an error and the error is oh I made this one and unforced and dropped one.

21
00:01:54,860 --> 00:02:00,140
So I have to actually make it an optional phone because we don't know if sender is they you want just

22
00:02:00,170 --> 00:02:00,980
recognize.

23
00:02:01,210 --> 00:02:03,430
Let me share the error once again.

24
00:02:03,810 --> 00:02:06,370
Let me read exactly the error that gave me.

25
00:02:06,670 --> 00:02:13,760
It's saying that for conditional binding must have an optional type so I'm going to say it is an optional

26
00:02:13,760 --> 00:02:14,630
type.

27
00:02:14,690 --> 00:02:22,690
OK so if that is the case then just say print and I'm going to train that before I run it.

28
00:02:22,730 --> 00:02:28,680
I want to show you that you just showed those Heather fine just to get a sense of what it has.

29
00:02:28,730 --> 00:02:30,750
It has number of caps required.

30
00:02:30,760 --> 00:02:32,030
That's something we can set.

31
00:02:32,240 --> 00:02:35,460
And the number of the touches that is required.

32
00:02:35,530 --> 00:02:39,200
So I think both of them are also here.

33
00:02:39,460 --> 00:02:44,200
So we could actually go in here and say a number of the types on the number of the touches.

34
00:02:44,380 --> 00:02:44,800
That's right.

35
00:02:44,800 --> 00:02:54,370
This is obviously the simplest of all the possible of gestures in here.

36
00:02:54,380 --> 00:02:59,900
I'm going to load up my console so I can see what I'm doing.

37
00:03:00,500 --> 00:03:03,000
And every time we type it says papped.

38
00:03:03,110 --> 00:03:07,700
So I think the final scene here let's go ahead and do something a little bit more elaborate.

39
00:03:07,710 --> 00:03:09,790
How about a going here.

40
00:03:10,180 --> 00:03:16,240
It's my tap gesture and I'm going to go to my library and look for a pen just gesture.

41
00:03:16,610 --> 00:03:23,350
So my pinch just you recognize has a scale so it can tell me how much I scale something.

42
00:03:23,590 --> 00:03:28,850
You know one of your upcoming lessons I would actually write this down myself when you say you can understand

43
00:03:28,850 --> 00:03:33,810
how you would go ahead to scale something using C.G. transform.

44
00:03:33,950 --> 00:03:39,530
But for now we going to read the value from the scale they have in your gesture and I said I'm going

45
00:03:39,530 --> 00:03:46,390
to go to View Controller get the connection and say that action my gesture action I'm going to connect

46
00:03:46,390 --> 00:03:48,230
it to this outlet.

47
00:03:48,330 --> 00:03:50,340
The pinched gesture victimiser.

48
00:03:50,630 --> 00:03:53,390
Let's go back to my view controller.

49
00:03:53,420 --> 00:03:55,450
I'm going to have to change all of this of course.

50
00:03:55,460 --> 00:04:05,650
I'm going to say if I let my pinch just is the send as you or I pinched just show recognizer.

51
00:04:05,900 --> 00:04:08,790
So now we have a pinch just should get nicer.

52
00:04:08,870 --> 00:04:19,340
Now we can get things such as a scale we can say the scale is and the value of it is might pinch that

53
00:04:19,430 --> 00:04:20,440
escape.

54
00:04:21,110 --> 00:04:29,390
And this is essentially a ratio between the current distance between the two taps and the previous one

55
00:04:30,230 --> 00:04:35,510
and that's about that it's giving me some warning which is I don't think that's a real thing.

56
00:04:35,510 --> 00:04:39,300
What does it say replace that.

57
00:04:39,380 --> 00:04:48,370
Blah blah blah blah know the value has been used I think this is one of those things that it gets a

58
00:04:48,370 --> 00:04:48,950
start.

59
00:04:48,990 --> 00:04:53,460
Next quote because my type just doesn't even exist anymore.

60
00:04:53,480 --> 00:04:55,190
Let me clean my.

61
00:04:56,800 --> 00:04:57,420
It's gone.

62
00:04:57,640 --> 00:05:02,270
And if you're wondering you clean the code using Come on shift then k.

63
00:05:02,490 --> 00:05:06,580
And that is hishe clean.

64
00:05:08,470 --> 00:05:11,360
Bill Yes it cleans everything up.

65
00:05:11,590 --> 00:05:11,940
OK.

66
00:05:11,980 --> 00:05:16,810
So let's go ahead and run this now in my simulator.

67
00:05:16,820 --> 00:05:20,730
Hopefully we should be able to see a scale happening.

68
00:05:22,580 --> 00:05:23,490
So I'm going to go in.

69
00:05:23,510 --> 00:05:24,260
Yeah.

70
00:05:24,450 --> 00:05:32,450
It's easy to see it gives me a scale which is essentially a ratio between the previous stands and the

71
00:05:32,450 --> 00:05:33,690
current one.

72
00:05:33,710 --> 00:05:41,070
If I clean this now on top in yet I move a little bit it says 1.00 some really a small number.

73
00:05:41,230 --> 00:05:45,950
And if I go further it becomes a larger one and a smaller one the smaller one.

74
00:05:45,950 --> 00:05:49,490
Now let me show you another few types of gestures.

75
00:05:49,490 --> 00:05:51,710
One of them is a tap.

76
00:05:51,710 --> 00:05:56,870
Just very used to treat your a Segway and let's see how you do that.

77
00:05:56,870 --> 00:06:03,050
And when I go in here and say have another you or you or another you have your controller rather and

78
00:06:03,050 --> 00:06:08,210
this you wave your controller I'm going to say it is a different background color.

79
00:06:08,420 --> 00:06:18,600
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.

80
00:06:19,780 --> 00:06:22,470
I want to cause a sync between these two.

81
00:06:22,670 --> 00:06:26,050
You know in a normal situation you could simply do this.

82
00:06:26,050 --> 00:06:30,790
You could go ahead of your controller even if your gesture happens.

83
00:06:30,790 --> 00:06:38,160
Assuming this is the gesture you want then you would say yes start performs say grace so on and so forth.

84
00:06:38,260 --> 00:06:42,800
Things that you have done before but now I want to do it in the visual interface.

85
00:06:42,940 --> 00:06:50,890
So here I'm going to go ahead and say Give me from this trap just sheriff Wickenheiser to the pink controller.

86
00:06:51,250 --> 00:06:52,530
Make sure.

87
00:06:52,840 --> 00:06:58,420
So essentially it becomes an input here in the trigger segue.

88
00:06:58,630 --> 00:07:05,260
So you could actually add them right here in the interface builder if you wanted to do a creature on

89
00:07:05,260 --> 00:07:07,990
this app even though you only know what is going to happen.

90
00:07:08,080 --> 00:07:14,840
The moment we tap we should essentially see a navigation to the other side which we go.

91
00:07:14,860 --> 00:07:16,660
Perfect that happens.

92
00:07:16,660 --> 00:07:23,830
Finally let me show you another kind of gesture which is kind of an important one and that is a UI rotation

93
00:07:23,830 --> 00:07:25,020
just should recognize.

94
00:07:25,020 --> 00:07:28,640
So this one location.

95
00:07:28,840 --> 00:07:34,390
So a rotation recognizer works like everybody else and has a rotation value.

96
00:07:34,480 --> 00:07:41,290
So if I go ahead in here into my view controller and say in the connections I have my gesture action

97
00:07:41,590 --> 00:07:52,650
connected to the rotation that's there I can go out of your control and say my roll my rotation or rotation

98
00:07:52,750 --> 00:08:02,950
just show recognizer is a your eye rotation just should recognize that I can say rotation is the value

99
00:08:02,950 --> 00:08:07,530
of the rotation dot rotation.

100
00:08:07,680 --> 00:08:15,640
And the reason I want to show you this is because the values that we will get in it is not in degrees.

101
00:08:15,780 --> 00:08:22,470
So if I begin rotating very good values that are of the type float if you want to convert this rotation

102
00:08:22,470 --> 00:08:34,500
into a degree value you could simply say Let my degree or that degree rotation harmers my rotation just

103
00:08:34,750 --> 00:08:41,290
dot rotation I'm going to multiply that one hundred and eighty and I'm going it's divided by pi.

104
00:08:41,460 --> 00:08:47,190
The only thing you have to keep in mind is that this fight is from the C-g flawed values.

105
00:08:47,300 --> 00:08:52,390
So it's going to be C.G. float dot PI and that's about that.

106
00:08:52,410 --> 00:08:58,680
That's the degree value of it up something I would recommend you doing is that you actually add an extension

107
00:08:58,680 --> 00:09:01,120
to your floating point NCG float.

108
00:09:01,260 --> 00:09:06,410
So I would think that going here and say extension C.G. fluid.

109
00:09:06,450 --> 00:09:08,620
I would add something to that.

110
00:09:08,790 --> 00:09:16,110
And then I would say another extension extension would be for binary integers with that other value

111
00:09:16,110 --> 00:09:17,030
in there.

112
00:09:17,190 --> 00:09:21,310
But I'll leave this for later when we do more exercises.

113
00:09:21,330 --> 00:09:27,870
For now when we get the rotation value we can simply go ahead and convert it manually every time.

114
00:09:28,070 --> 00:09:34,750
Let me run this now and it should give us this time to rotation in a degree mode.

115
00:09:34,800 --> 00:09:43,380
So if I go in here and I rotate this much it was 20 30 40 60 90 degrees one hundred and eighty degrees.

116
00:09:43,380 --> 00:09:46,800
Numbers are a little bit more more familiar to our minds.

117
00:09:46,800 --> 00:09:48,220
I personally don't know.

118
00:09:48,420 --> 00:09:54,110
I mean I know how radians work but I can't really imagine the radium values as easily.

119
00:09:54,360 --> 00:09:56,110
So that's about that.

120
00:09:56,190 --> 00:10:02,970
We talked about tap just shows a scale of just sheer Penge gesture and rotation just for a number of

121
00:10:02,970 --> 00:10:09,570
other gestures in here I suggest that you try them on your own such as a slight gesture and a pine and

122
00:10:09,570 --> 00:10:15,080
just short of a long press just for each of them has their own set of attributes.

123
00:10:15,090 --> 00:10:22,110
They do things such as a swipe just shake can have a direction in which you can swipe and causes something

124
00:10:22,110 --> 00:10:30,690
to happen or a long press gesture has a certain length that you have to press a minimum duration that

125
00:10:30,690 --> 00:10:33,360
you have to press before it is being triggered.

126
00:10:33,630 --> 00:10:36,920
And yet that's about just shows on you in the next.
