1 00:00:00,480 --> 00:00:07,400 Sober come back again in this exercise we're going to use a combination of a wire rotation just to recognize 2 00:00:07,400 --> 00:00:13,120 that I you I pinched the riser to rotate on a scale a wide view. 3 00:00:13,310 --> 00:00:15,940 So I'm going to pause the video for a few seconds. 4 00:00:15,980 --> 00:00:17,480 You give it a shot on your own. 5 00:00:17,510 --> 00:00:20,750 And then if you wanted to can follow along with my solution as well. 6 00:00:23,620 --> 00:00:23,970 OK. 7 00:00:24,010 --> 00:00:32,070 So I'm going to go to Mexico now and I'm going to start a new project called Just shows and transform 8 00:00:33,010 --> 00:00:36,420 because that's essentially what it is a transformation. 9 00:00:36,770 --> 00:00:47,780 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. 10 00:00:47,790 --> 00:00:52,920 As always this part of the work I'm actually going to go through them quite quickly because I know that 11 00:00:53,280 --> 00:00:57,150 you guys know exactly how to do it you don't really need my help with it. 12 00:00:57,190 --> 00:01:04,220 So this is the red box and that's all I need in my interface field. 13 00:01:04,570 --> 00:01:07,680 Now my actual programming is swift. 14 00:01:07,710 --> 00:01:16,920 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 15 00:01:16,920 --> 00:01:19,230 just for recognizer. 16 00:01:19,290 --> 00:01:27,930 I'm going to have a vowel let's call it scaler just it's going to be a u i pinch gesture recognizer. 17 00:01:28,350 --> 00:01:29,990 Now in my view a lot. 18 00:01:30,000 --> 00:01:33,900 I'm going to go ahead and essentially initialize both of them. 19 00:01:33,930 --> 00:01:40,320 There is really practically no difference between doing both of these in the interface there or if you 20 00:01:40,320 --> 00:01:45,660 want to do it here in the court are would both work exactly identically with on one end within the code 21 00:01:45,660 --> 00:01:47,970 so that we get to see it here as well. 22 00:01:48,240 --> 00:01:55,030 So it just becomes you like rotation just for recognizer of yourself. 23 00:01:55,110 --> 00:01:58,830 And we need to have an action with a selector. 24 00:01:58,830 --> 00:02:05,030 So I'm going to say that action is called rote action or something to that effect. 25 00:02:05,490 --> 00:02:14,050 And then I'm going to have to say I have a scale gesture which is going to be a I pinched gesture recognizer 26 00:02:14,280 --> 00:02:24,600 with Target's self and action being a selector Salek the center of a scale action. 27 00:02:24,600 --> 00:02:26,910 So now I need to have both of these actions. 28 00:02:26,970 --> 00:02:32,550 So I'm going to say a function rotation action and it has an arc. 29 00:02:32,610 --> 00:02:36,180 It doesn't actually need to have an argument so there isn't. 30 00:02:36,180 --> 00:02:42,420 I thought first I can have the argument is because I wanted to get the gesture but the gestures already 31 00:02:42,420 --> 00:02:45,210 have a kind of a global variable. 32 00:02:45,300 --> 00:02:47,570 So I don't need to have an argument here. 33 00:02:47,940 --> 00:02:55,470 So I have a rotation action and I have the other one which is called the scalar action and that's that 34 00:02:55,470 --> 00:02:56,180 one. 35 00:02:56,310 --> 00:03:03,630 Finally in my view that note I'm going to have to say we should add both of these to our red box. 36 00:03:03,630 --> 00:03:13,030 So when I say red box dot I'll just show recognizer Roths gesture and the red box thought I just recognize 37 00:03:13,590 --> 00:03:15,030 the scale gesture. 38 00:03:15,390 --> 00:03:21,410 And finally this is giving me an error saying that your selector methods are not exposed as objective 39 00:03:21,420 --> 00:03:22,070 see. 40 00:03:22,410 --> 00:03:24,400 So I'm going to have to do two. 41 00:03:24,420 --> 00:03:26,760 This is something we have seen many times before. 42 00:03:26,820 --> 00:03:32,550 The part of swift for I'm guessing and the new versions this will be this will be gone. 43 00:03:32,550 --> 00:03:33,700 So that's about that. 44 00:03:33,720 --> 00:03:39,330 My view of the lot of both of the gestures are initialized underboss applied to the red box. 45 00:03:39,570 --> 00:03:43,700 And now we have to actually do teams with them in their functions. 46 00:03:43,860 --> 00:03:50,280 So I'm going to fold this one and I'm going to go to my rotation action and say in the rotation action 47 00:03:50,740 --> 00:03:58,790 red box dot transforms becomes red box start transformed those rotated. 48 00:03:59,190 --> 00:04:04,630 And the value of they want rotate is the rotation of the rotation gesture. 49 00:04:04,710 --> 00:04:13,490 I'm going to say let's new wrote to be rotations just sheer dot rotation and I'm going up right. 50 00:04:13,490 --> 00:04:15,530 Got C.G. fruit in here. 51 00:04:15,570 --> 00:04:17,500 Now I'm working on this application. 52 00:04:17,520 --> 00:04:22,770 Even though I know it is not going to work because I want to show you something that is a very important 53 00:04:22,770 --> 00:04:27,940 concept something that is going to go wrong now and we have to fix it once it loads. 54 00:04:27,960 --> 00:04:34,470 We should see some really unexpected results so if I try to do this you can see that it's rotating with 55 00:04:34,530 --> 00:04:36,530 really unexpected values. 56 00:04:36,540 --> 00:04:43,640 And the reason for it is this the value of the rotation just is constantly adding to itself. 57 00:04:43,650 --> 00:04:49,630 So if I'm rotating these and try to only look at the two tops that I have on the screen you find rotate 58 00:04:49,650 --> 00:04:52,630 this say 90 degrees which is like this. 59 00:04:52,740 --> 00:04:59,170 That's going to be 90 degrees that is being recorded into my rotation just share and then when I wrote 60 00:04:59,170 --> 00:05:05,010 it down under 90 degrees the first 90 degrees and the second one are getting our data to each other. 61 00:05:05,130 --> 00:05:10,950 So it's kind of adding the values one is there by the time itself and to remedy that well you're going 62 00:05:10,950 --> 00:05:17,910 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 63 00:05:17,910 --> 00:05:22,460 in here and say well we got the value we rotated the red box. 64 00:05:22,470 --> 00:05:25,950 Now you have to reset to zero. 65 00:05:26,180 --> 00:05:28,470 So let's go ahead and check it out again. 66 00:05:28,510 --> 00:05:35,170 What I read on the application and this time in every roll cycle we're going to add a little rotation 67 00:05:35,170 --> 00:05:36,180 to the red box. 68 00:05:36,300 --> 00:05:43,680 But then it's going to zero itself out and if we rotate the way we wanted rotate so what station is 69 00:05:43,680 --> 00:05:46,110 working the way you want it to rotate. 70 00:05:46,110 --> 00:05:54,030 So that's one thing that you have to keep in mind that the amount of rotation is actually being constantly 71 00:05:54,120 --> 00:05:58,640 added tweets if we will face a very similar situation with this scale. 72 00:05:58,650 --> 00:06:08,520 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 73 00:06:08,520 --> 00:06:15,330 this value is actually constantly multiplying itself by the previous one because it's a ratio so the 74 00:06:15,330 --> 00:06:18,650 ratio is based on the default value of one. 75 00:06:18,710 --> 00:06:23,330 And now he's saying well it's now 1.1 times of the previous one. 76 00:06:23,520 --> 00:06:28,830 And then when it gets another one it's not going to multiply by the default one is going to multiply 77 00:06:28,860 --> 00:06:32,230 by the previous one which is not something we want. 78 00:06:32,250 --> 00:06:41,330 So I'm going to say Redbox not transform transform is going to be a red box not transform the scale 79 00:06:41,360 --> 00:06:42,180 the boy. 80 00:06:42,400 --> 00:06:46,670 And the value we want is the newest scale for both x and y. 81 00:06:47,070 --> 00:06:54,210 Newer scale but once I'm done with that I'm going to say a scale just sheer scale defaulted back to 82 00:06:54,210 --> 00:06:54,770 one. 83 00:06:54,840 --> 00:06:57,690 Don't keep the current value in it. 84 00:06:57,690 --> 00:06:59,130 So I'm going to run this again. 85 00:07:00,940 --> 00:07:09,370 And now we can scale properly and we can also rotate properly sometimes that the gesture doesn't really 86 00:07:09,370 --> 00:07:15,310 recognize which one you're trying to do with a rotation you're attempting or it is the escape tempting 87 00:07:15,580 --> 00:07:17,360 but that's perfectly fine. 88 00:07:17,360 --> 00:07:22,150 And yeah that's that's why I have to tell you about these two guys. 89 00:07:22,180 --> 00:07:25,120 There is another thing that you might want to keep an eye on. 90 00:07:25,120 --> 00:07:32,020 And that's the state of a gesture recognizer are the states are very similar to the same states that 91 00:07:32,020 --> 00:07:33,150 we have for touches. 92 00:07:33,150 --> 00:07:35,740 They are begin are unchanged. 93 00:07:35,750 --> 00:07:39,250 And so sometimes you can actually do things. 94 00:07:39,270 --> 00:07:42,620 It just shows doors and or does begin. 95 00:07:42,820 --> 00:07:48,670 And you can obviously read up on all of those on on the manual under header files as well. 96 00:07:48,700 --> 00:07:52,210 So that was it made this exercise and I would you in the next lesson.