Autosizing Multiple Views in a Window

Most windows that contain scrollers should be resizable. In Chapter 10, we showed how to set up an NSScrollView so that it would resize when its containing window was resized. Recall that we set the Autosizing attributes for the NSScrollView in IB’s Size Info dialog. That was easy to do for our MathPaper application because there was only one view — the NSScrollView — that covered the window’s content area. With the ViewDemo window, however, handling window resizing requires a little more thought because there are multiple view objects. Let’s first see what the current situation is.

  1. Back in IB with PolygonView, choose the File Test Interface menu command.

  2. Resize the window up and to the left. Note that the view objects in the window don’t change size and thus become obscured when the window is small, as shown in the window on the left in Figure 15-11.

Problems with resizing in ViewDemo

Figure 15-11. Problems with resizing in ViewDemo

  1. Now resize the window down and to the right, and note that the objects still don’t change size or position relative to the lower-left corner. The result is ugly, as shown in the window on the right in Figure 15-11.

  2. Quit Test Interface mode by typing Command-Q.

  3. Select the NSScrollView/PolygonView instance and type Command-3 to bring up IB’s Size Info dialog with the Autosizing feature.

  4. Click the lines in the inner Autosizing square so that the four ...

Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.