1 00:00:00,560 --> 00:00:01,940 So welcome back again. 2 00:00:01,940 --> 00:00:07,640 In this lesson we're going to talk about a new eye popping over presentation and that's essentially 3 00:00:07,640 --> 00:00:14,930 a kind of Segway that makes one view controller to appear over the other one although it is possible 4 00:00:14,930 --> 00:00:17,360 to use a UI Popova as in iPhone. 5 00:00:17,360 --> 00:00:23,750 We use them primarily for iPod interfaces because there's more space and you can actually see verities 6 00:00:23,750 --> 00:00:26,540 appeared on top of the other view controller. 7 00:00:26,600 --> 00:00:31,150 So let's go ahead into export and develop one and get a sense of how we do that. 8 00:00:31,220 --> 00:00:34,670 And when I start a new application I'm going to accommodate you. 9 00:00:34,680 --> 00:00:42,850 I pop over app and then the moment my UI pop all the tabloids I'm going to change the simulator type 10 00:00:42,860 --> 00:00:49,460 to be a part any type of iPod that would do for now I'm just going to leave that iPod sixth generation 11 00:00:50,760 --> 00:00:53,660 and the next thing I need to do I'm going to head into this storyboard. 12 00:00:53,720 --> 00:01:01,320 And in here I'm going to assume that I have my view shown as an iPod view something like that. 13 00:01:01,620 --> 00:01:04,480 And then you know I'm going to assume that they have a button. 14 00:01:04,530 --> 00:01:11,990 So it's have a by then I'm going to play see it maybe here right in the center. 15 00:01:12,000 --> 00:01:18,830 Actually that means I mean truth little bit more gets rid of that. 16 00:01:18,830 --> 00:01:23,310 So here's my by then and by then I'm going to give it a different background color. 17 00:01:23,330 --> 00:01:28,530 Maybe like that and it says tap to pop. 18 00:01:28,910 --> 00:01:32,350 And the thing I want to happen is I want to press this button. 19 00:01:32,360 --> 00:01:34,950 I want a boy pop over to appear. 20 00:01:35,090 --> 00:01:42,620 And once that one appears I want to have something in there that changes a value in my main view contract 21 00:01:42,950 --> 00:01:43,790 which is this one. 22 00:01:44,210 --> 00:01:48,500 So to do that the first thing I need is I need a new view controller. 23 00:01:48,540 --> 00:01:55,460 So I'm going to go in here say I have a new view controller and this new view controller I'm actually 24 00:01:55,460 --> 00:02:03,200 going to go to the attributes of it and say its size is not in fact it's rather a freeform one so you 25 00:02:03,200 --> 00:02:12,200 can actually go in here in the dimensions and manually change its size so your size is maybe 300 by 26 00:02:12,200 --> 00:02:13,100 300. 27 00:02:13,370 --> 00:02:19,380 So I make them much smaller of your controller because I don't want to cover the entire screen. 28 00:02:19,430 --> 00:02:23,850 So this new view controller may be a make its back on to be the same color. 29 00:02:23,870 --> 00:02:25,300 Something like that. 30 00:02:25,640 --> 00:02:32,700 And then I'm going to go ahead and say from my button top to pop I'm going to make a Segway to here. 31 00:02:32,820 --> 00:02:37,550 And that Segway is actually going to be of the type present as pop over. 32 00:02:38,090 --> 00:02:45,020 So now I have that Segway that presents this view controller as a pop over and if I select my Segway 33 00:02:45,050 --> 00:02:48,380 I can see that they have this set as a pop over. 34 00:02:48,410 --> 00:02:53,210 There are directions that I will talk to you about in a second and I'm going to give it an identifier 35 00:02:53,210 --> 00:02:53,620 as well. 36 00:02:53,660 --> 00:03:01,690 I'm going to say my Segway I.D. now could actually run the application right now and see what we get 37 00:03:01,690 --> 00:03:02,530 and let's do that. 38 00:03:02,530 --> 00:03:09,940 Just let me get a sense of what happens up until this point if we just have a Segway of the type you 39 00:03:10,010 --> 00:03:17,150 pop over a presentation with a view controller that is a smaller than the regular sized if I type on 40 00:03:17,150 --> 00:03:17,470 you. 41 00:03:17,510 --> 00:03:24,110 We see that my view controller appears here on the top left corner and it doesn't really stay true to 42 00:03:24,110 --> 00:03:30,020 the values that we suggested the values of being 300 by 300 pixels. 43 00:03:30,020 --> 00:03:35,620 So let's go ahead and modify all of these things manually so we know exactly what is going to show up 44 00:03:35,920 --> 00:03:39,890 and we know exactly what size is going to have sought to do that. 45 00:03:39,890 --> 00:03:44,900 I'm going to go to my view controller and in my view controller I need to call for a method that is 46 00:03:45,170 --> 00:03:49,510 preparing for a segue ways because this is after all another Segway. 47 00:03:49,630 --> 00:03:55,280 So I'm going to say prepare for saving and it might prepare for a Segway I'm going to go ahead and say 48 00:03:55,370 --> 00:04:03,770 if Segway dot identifier laws that I.D. Of course you don't really have to do that because in year we 49 00:04:03,770 --> 00:04:05,290 only have one Segway. 50 00:04:05,300 --> 00:04:08,600 But the real application you might have multiple one of those. 51 00:04:08,600 --> 00:04:09,920 So I'm going to do it for now. 52 00:04:09,920 --> 00:04:13,660 But if you only had one Segway then you don't need to bother with that. 53 00:04:13,700 --> 00:04:19,040 So the first thing I'm going to do is I'm going to say let let's call it the V.C. and we have to get 54 00:04:19,040 --> 00:04:22,060 the same way that destination view controller. 55 00:04:22,190 --> 00:04:28,910 And we have to make that of a certain type simply because we don't know what is the type of this view 56 00:04:28,910 --> 00:04:29,890 controller. 57 00:04:29,900 --> 00:04:35,150 So for that I'm going to actually have to make a new view controller class I'm going to say command 58 00:04:35,240 --> 00:04:43,520 and that's going to be a Coco touch class of the type you I view controller and I'm going to call that 59 00:04:43,520 --> 00:04:45,280 pop fuel controller. 60 00:04:45,740 --> 00:04:49,310 So I have a view controller it's called pop view controller. 61 00:04:49,370 --> 00:04:52,720 I don't want anything in here actually I want to get rid of everything. 62 00:04:53,900 --> 00:05:00,170 And what I want to do is I want to go to my storyboard and assign that to be the class for the little 63 00:05:00,170 --> 00:05:01,100 of your controller. 64 00:05:01,100 --> 00:05:05,690 So for this view controller it's actually called Pop view controller. 65 00:05:06,140 --> 00:05:08,360 So we've got that part taken care of. 66 00:05:08,360 --> 00:05:13,110 Now I'm going to go back to the view controller and say in preparation for a Segway. 67 00:05:13,120 --> 00:05:18,680 Get the V C to be as a pop view controller. 68 00:05:18,680 --> 00:05:21,980 Because I know there's going to be of that type anyway. 69 00:05:22,040 --> 00:05:29,150 Now the next thing I need to do is I need to find a content size for this pop view controller. 70 00:05:29,180 --> 00:05:38,170 So I'm going to go ahead and say let's have a v c and I'm going to say preferred content size. 71 00:05:38,240 --> 00:05:45,520 I'm going to say that it's a C G size of our 300 and 300 the numbers that you want. 72 00:05:45,740 --> 00:05:50,030 So we're setting those values to be exactly 300 by 300. 73 00:05:50,030 --> 00:05:54,950 Now so far everything we have done has been on setting the view controller itself. 74 00:05:54,950 --> 00:05:58,670 We haven't done anything on the pop over controller. 75 00:05:58,670 --> 00:06:03,710 The controller that actually makes sure your view appears on top of another view. 76 00:06:03,710 --> 00:06:08,900 So to do that I'm actually going to go ahead and say let and I'm going to call it controller. 77 00:06:09,020 --> 00:06:16,870 I'm going to say that becomes a V.C. pop over view presentation controller so I essentially find the 78 00:06:16,870 --> 00:06:24,610 pop over presentation controller of this view controller and then I'm going to say controller dot Daggett 79 00:06:24,970 --> 00:06:31,350 which is of the type you pop over presentation controller that I get to be self. 80 00:06:31,380 --> 00:06:36,080 And since I'm delegating to here I obviously have to have that protocol conform to. 81 00:06:36,090 --> 00:06:45,580 So I'm going to say it's called the UI pop over presentation controller delegate so I conform to that 82 00:06:45,580 --> 00:06:46,780 delegate as well. 83 00:06:46,940 --> 00:06:50,140 And now I can actually change the settings of this controller. 84 00:06:50,230 --> 00:06:55,670 So the first thing I'm going to do is I'm going to say controller dot source view. 85 00:06:55,690 --> 00:06:58,010 It becomes self that the view. 86 00:06:58,060 --> 00:07:00,710 So it appears from this view controller. 87 00:07:00,910 --> 00:07:06,550 So the next thing I want to set is I want to set in which direction does the controller actually appear. 88 00:07:06,550 --> 00:07:18,310 So I'm going to say controller dot permit that method our direction becomes a UI I pop over arrow direction 89 00:07:18,730 --> 00:07:26,680 dot up and that essentially means that I want my UI pop over to appear at the bottom of something whatever 90 00:07:26,710 --> 00:07:27,640 that triggers it. 91 00:07:27,640 --> 00:07:32,880 In this case being my button now the next thing is actually quite important somehow. 92 00:07:32,950 --> 00:07:34,030 Tricky. 93 00:07:34,030 --> 00:07:40,900 And that's about the Verdi you want the arrow to appear and based on that everything yes finds its place. 94 00:07:40,900 --> 00:07:47,950 So that's essentially called controller dot source rect and this for select is essentially the location 95 00:07:47,950 --> 00:07:50,500 where you won the arrow to appear from. 96 00:07:50,860 --> 00:07:53,370 Let me first show you what I mean by that. 97 00:07:53,380 --> 00:07:57,580 And then I'm going to you know play around with the numbers so you can see it a little bit better. 98 00:07:57,940 --> 00:08:01,250 So I'm going to say there's a siege erect and is God. 99 00:08:01,330 --> 00:08:03,390 All of these four values. 100 00:08:03,880 --> 00:08:07,930 I don't want its width and height to have any value so the 0 1 0. 101 00:08:07,930 --> 00:08:11,460 So there's just one location for the Exo feet. 102 00:08:11,470 --> 00:08:15,090 I'm going to say let it be in the center of the button. 103 00:08:15,190 --> 00:08:17,240 The button that is calling it. 104 00:08:17,260 --> 00:08:25,010 So for that I actually have to get my Sander and say here's let's just put it in a button. 105 00:08:25,010 --> 00:08:31,400 So let's say my button becomes sender as you. 106 00:08:31,400 --> 00:08:37,710 I buy then because I know it is a button anyway so I'm going to say get the button from the button. 107 00:08:37,730 --> 00:08:40,420 I want to find its center. 108 00:08:40,700 --> 00:08:42,870 And it's centered I want to get X off it. 109 00:08:43,160 --> 00:08:48,590 So that is the location that they want for the X and I want the very same thing or a very similar thing 110 00:08:48,590 --> 00:08:49,290 for the Y. 111 00:08:49,820 --> 00:08:56,420 So I won the source straight to appear from the center of my by then in both X and Y and they don't 112 00:08:56,420 --> 00:08:58,270 have any Veit or heights with them. 113 00:08:58,730 --> 00:09:03,310 Let's go ahead and run this application up until now and then we get a better sense of what this source 114 00:09:03,330 --> 00:09:11,940 select is actually doing so now with my app is on if I tap on here you will see that the arrow actually 115 00:09:11,940 --> 00:09:18,750 appears from the center of this button and that is essentially what this source strict means. 116 00:09:18,750 --> 00:09:25,980 If I wanted the arrow to appear on the lower left corner of the button I would say my button dot frame 117 00:09:26,940 --> 00:09:35,310 dot origin dot X that is the X of it and then I would go ahead and see for the value of it make it my 118 00:09:35,310 --> 00:09:35,850 button. 119 00:09:35,870 --> 00:09:40,550 Center y and then I would add the height of my button to it as well. 120 00:09:40,740 --> 00:09:48,650 I would say plus my button dot bounds dot height so I would add that much to it. 121 00:09:48,650 --> 00:09:53,560 Let me get a little bit of a space in here and then you ran for the via Ft. 122 00:09:53,580 --> 00:09:55,590 I will actually put the origin of it. 123 00:09:55,680 --> 00:10:03,570 So this essentially means the top left corner in terms of the Y plus the height of the button which 124 00:10:03,600 --> 00:10:08,400 essentially translates into the lower left corner. 125 00:10:08,670 --> 00:10:10,110 Let's see if that is true. 126 00:10:10,130 --> 00:10:10,550 It's rich. 127 00:10:10,550 --> 00:10:17,730 Show me the pop over in the lower left corner of the bar then now when the application runs. 128 00:10:17,730 --> 00:10:23,330 So now when I tap in here I will see that it appears from the lower left. 129 00:10:23,370 --> 00:10:28,260 I don't know if you can see the arrow it has a has a white little thing which is a little difficult 130 00:10:28,260 --> 00:10:34,020 to see for they could do they could actually change my background color so we could see that one a little 131 00:10:34,020 --> 00:10:37,880 bit easier while I'm in the storyboard and changing the background. 132 00:10:37,890 --> 00:10:40,110 This fixed a few other things as well. 133 00:10:40,200 --> 00:10:44,180 You want the masses to pass between these two view controllers. 134 00:10:44,260 --> 00:10:51,060 Someone going here and say I have a button in the new View Controller in their pop view controller on 135 00:10:51,060 --> 00:10:51,590 this one. 136 00:10:51,600 --> 00:10:59,550 It actually has a maybe a white background and it says send message. 137 00:11:01,620 --> 00:11:02,310 OK. 138 00:11:02,430 --> 00:11:06,270 And the next thing I'm going to do is I'm actually going to set all the constraints for it. 139 00:11:06,310 --> 00:11:11,880 I'm going to say ad all missing constraints and then I'm going to go ahead and say there is a label 140 00:11:11,880 --> 00:11:15,710 in here and this is the one that is going to receive the message. 141 00:11:15,720 --> 00:11:20,860 So I'm going to place third Labor in here say my label is a bit larger. 142 00:11:21,120 --> 00:11:23,680 And it also has a white background. 143 00:11:23,940 --> 00:11:31,200 And now I have to set the outlets for both of these items and I also have to set the delegation pattern 144 00:11:31,200 --> 00:11:31,700 for them. 145 00:11:32,140 --> 00:11:38,600 So I'm going to go in here and say in my main view controller This is my labor. 146 00:11:38,730 --> 00:11:48,330 So this is called My labor in my other view controller in the pop view controller I'm going to go ahead 147 00:11:48,330 --> 00:11:55,650 and say This one is actually an action that says send message. 148 00:11:55,680 --> 00:12:00,240 Action. 149 00:12:00,630 --> 00:12:05,000 So then I'm going to go to the pop view controller and say yeah. 150 00:12:05,040 --> 00:12:07,200 I actually have a protocol. 151 00:12:07,620 --> 00:12:11,750 I usually put this in a separate file but it doesn't really matter in here. 152 00:12:11,760 --> 00:12:21,390 So when I say pop action that I get and only has one function that says send the message and the message 153 00:12:21,390 --> 00:12:27,210 of it has an impact text which is a string of course. 154 00:12:27,470 --> 00:12:31,230 And since it is in the protocol we don't need the body of the function. 155 00:12:31,350 --> 00:12:35,000 And now my pop view controller it has a delegate. 156 00:12:35,160 --> 00:12:43,770 So I'm going to go ahead and say variable delegate after type pop action delegate. 157 00:12:43,770 --> 00:12:52,740 And every time that the send the message is called do this say self that delegate dot sends the message 158 00:12:53,070 --> 00:12:55,620 and the message says from Pop. 159 00:12:55,740 --> 00:13:00,660 Just like what we have done many many many times before with the delegation patterns. 160 00:13:00,660 --> 00:13:09,090 So now this view controller and this protocol essentially are ready to send a message to the delegation. 161 00:13:09,090 --> 00:13:15,780 The only thing is left for me to do is go to my view controller in here when I find the V.C. of the 162 00:13:15,780 --> 00:13:23,730 type view controller I'm going to say we see that delegate becomes a self and since I'm trying to delegate 163 00:13:23,760 --> 00:13:31,200 this view controller as this kind of delegation I need to make sure that this thing is also their pop 164 00:13:31,260 --> 00:13:35,680 action that they get is one of the protocols were conforming to it. 165 00:13:36,180 --> 00:13:38,890 So my view controller conforms with that as then. 166 00:13:39,180 --> 00:13:45,630 And then it's telling me that if you are trying to conform to this you must include that function and 167 00:13:45,630 --> 00:13:51,630 that function is called I think send the message and I'm going to say every time you receive a message 168 00:13:51,630 --> 00:13:53,040 showing it on my labor. 169 00:13:53,490 --> 00:14:02,900 So my labor that text becomes input text whatever value you find from whoever has called the delegation. 170 00:14:02,910 --> 00:14:08,490 Now before I run the application I want to quickly change something else as well and that is I want 171 00:14:08,490 --> 00:14:13,100 to come in here and say very we see the source rectangle. 172 00:14:13,110 --> 00:14:15,010 I want it to be at the center. 173 00:14:15,240 --> 00:14:19,050 So my by then Dart Center. 174 00:14:19,050 --> 00:14:25,060 That X and for the value of it I want it to be my by then that center. 175 00:14:25,060 --> 00:14:29,610 That's why I want to show right at the bottom of my button. 176 00:14:29,790 --> 00:14:37,860 And then I want to push it down maybe as much as maybe a half of the half of the height or any other 177 00:14:37,860 --> 00:14:40,550 number that you can just manually place in there. 178 00:14:40,560 --> 00:14:45,470 I don't want to appear on top of my by then because right now then we place person. 179 00:14:45,480 --> 00:14:48,400 It actually appears right at the bottom of it. 180 00:14:48,420 --> 00:14:53,850 And I went up here down in here and not in the center like the last time. 181 00:14:53,850 --> 00:15:00,390 So with that in mind if you go ahead then we rerun our application we should have it up appearing right 182 00:15:00,390 --> 00:15:05,540 at the bottom of the button and it should actually interact with the view as well. 183 00:15:05,550 --> 00:15:13,050 So if I go here and I zoom a little bit if I pop it appears here and then if I have to send my message 184 00:15:13,140 --> 00:15:20,250 it sends a message to here which is essentially the goal of having a pop over a view controller controlling 185 00:15:20,250 --> 00:15:22,560 something in here. 186 00:15:22,650 --> 00:15:24,290 So that's almost about it. 187 00:15:24,300 --> 00:15:29,020 How to have a pop over a controller and how to communicate between the two of them. 188 00:15:29,030 --> 00:15:33,270 There is one other thing that I'm just going to show you I'm not going to really do it because it doesn't 189 00:15:33,270 --> 00:15:42,120 work on this application and that is something that we call controller dot bar by then IDM and you use 190 00:15:42,120 --> 00:15:49,940 this essentially instead of using a source correct if you are going to call your controller from a bar 191 00:15:49,950 --> 00:15:57,000 by then IDM from your navigation bar or from your bottom bar if you want your controller to appear from 192 00:15:57,030 --> 00:16:04,590 a certain bar by then item then you call this one which essentially overrides the source rect and makes 193 00:16:04,590 --> 00:16:12,510 sure that your controller shows up from that particular item on your bar and that's you know useful 194 00:16:12,510 --> 00:16:17,250 in situations where you're using a navigation bar or something of the source. 195 00:16:17,340 --> 00:16:18,630 So that's about it. 196 00:16:18,660 --> 00:16:22,610 Let's keep it up to here and we'll move on to our next lesson.