1 00:00:00,700 --> 00:00:02,560 Before we go any further, 2 00:00:02,560 --> 00:00:06,780 it's time to discuss what the differences between frame and bounds. 3 00:00:08,030 --> 00:00:13,570 The short answer to the question is that the bounds of a UI view is the rectangle 4 00:00:13,570 --> 00:00:19,010 expressed as a location xy, and size within height relative 5 00:00:19,010 --> 00:00:24,430 to its own coordinate system The frame, on the other hand, is a rectangle, as well. 6 00:00:24,430 --> 00:00:28,730 Again, expressed as a location xy in size, width, and height. 7 00:00:28,730 --> 00:00:32,290 But this time, relative to the super view it is contained within. 8 00:00:33,700 --> 00:00:36,830 Though these are precise and succinct definitions, 9 00:00:36,830 --> 00:00:40,960 if you're not familiar with view geometry, they might seem a bit cryptic. 10 00:00:42,430 --> 00:00:47,830 A longer explanation, one that should make these definitions a bit more meaningful, 11 00:00:47,830 --> 00:00:50,710 needs to start with the reason why there needs to be 12 00:00:50,710 --> 00:00:54,520 two ways of specifying the rectangle that defines a UI view. 13 00:00:55,930 --> 00:00:58,890 This need arises from the system that makes 14 00:00:58,890 --> 00:01:01,940 programming a complex view hierarchy manageable. 15 00:01:02,990 --> 00:01:08,220 For a concrete example of the potential complexity inherent in a view hierarchy, 16 00:01:08,220 --> 00:01:11,750 imagine you have a device running a simple app. 17 00:01:11,750 --> 00:01:16,300 Lets imagine that it is a UIview with a couple of subviews. 18 00:01:16,300 --> 00:01:20,300 Then suppose your app displays a pop-up which is a view and 19 00:01:20,300 --> 00:01:23,120 in this pop-up there's a button which is also a view. 20 00:01:24,280 --> 00:01:28,980 What makes programming the buttons layout inside the popup manageable 21 00:01:28,980 --> 00:01:32,920 is the buttons ignorance of all other views in the hierarchy. 22 00:01:34,160 --> 00:01:37,330 If views were required to understand their layouts 23 00:01:37,330 --> 00:01:41,770 in terms of device screen coordinates in order to join the view hierarchy, 24 00:01:42,770 --> 00:01:48,010 then they would be required to know of all the layouts of all their superviews. 25 00:01:48,010 --> 00:01:49,700 Needing to address this complexity, 26 00:01:49,700 --> 00:01:55,220 within each view would make constructing view hierarchies nearly impossible. 27 00:01:55,220 --> 00:01:57,030 Thankfully, in our example, 28 00:01:57,030 --> 00:02:02,090 the hypothetical button only needs to understand its layout within the popup. 29 00:02:02,090 --> 00:02:06,055 And in turn the popup only needs to know how it sits in its superview. 30 00:02:07,720 --> 00:02:11,830 Each view provides a simple limited world for it sub views 31 00:02:11,830 --> 00:02:15,440 that are given to believe that the superview sits at coordinates zero zero. 32 00:02:16,610 --> 00:02:21,190 This simplified reality that a view shares with its sub views is called the views 33 00:02:21,190 --> 00:02:21,789 bounds. 34 00:02:22,950 --> 00:02:25,700 The frame is where the sub view thinks it 35 00:02:25,700 --> 00:02:29,100 exists in terms of the bounds provided by its parent. 36 00:02:30,340 --> 00:02:34,850 The frame is the reality of viewshares with its superview 37 00:02:34,850 --> 00:02:39,270 while the bounds is the reality it presents to it subviews. 38 00:02:39,270 --> 00:02:40,770 And this is a complicated topic. 39 00:02:40,770 --> 00:02:44,560 So don't worry if it doesn't make complete sense immediately. 40 00:02:44,560 --> 00:02:48,290 More information about frame and balance can be found in the teacher's notes.