Size-Class-Specific Layout一流的特异性布局尺寸
Storyboards in Interface Builder by default use size classes. Size classes are traits assigned to user interface elements, like scenes or views. They provide a rough indication of the element’s size. Interface Builder lets you customize many of your layout’s features based on the current size class. The layout then automatically adapts as the size class changes. Specifically, you can set the following features on a per-size-class basis:
故事板在使用界面生成器默认大小班。大小特征的类分配到一个用户界面元素,或视图类。他们提供了一个粗略的指示元素的大小。我让你自定义界面生成器的功能布局的基础上的电流的大小类。布局,然后自动适应大小的变化是一流的。特别是,你可以通过下面的特征集上的大小类的基础:
-
Install or uninstall a view or control.安装或卸载视图或控件。
-
Install or uninstall a constraint.安装或卸载约束。
-
Set the value of select attributes (for example, fonts and layout margin settings).设置选择属性的值(例如,字体和布局边距设置)。
When the system loads a scene, it instantiates all the views, controls, and constraints, and assigns these items to the appropriate outlet in the view controller (if any). You can access any of these items through their outlets, regardless of the scene’s current size class. However, the system adds these items to the view hierarchy only if they are installed for the current size class.
当系统负载的场景,它实例化的所有视图,控制和约束,并将这些物品在视图控制器的相应的插座(如果有)。您可以访问任何这些项目通过他们的网点,无论场景的当前大小类。但是,系统只将这些项添加到视图层次结构,如果它们为当前大小类安装。
As the view’s size class changes (for example, when you rotate an iPhone or switch an iPad app between full-screen and Split View), the system automatically adds items to or removes them from the view hierarchy. The system also animates any changes to the view’s layout.
由于视图的大小类改变(例如,当您在全屏和拆分视图之间旋转iPhone或切换iPad应用程序时),系统会自动从视图层次结构中添加或移除这些项。该系统还将任何更改视图的布局。
NOTE
The system keeps a reference to the uninstalled items, so they are not deallocated when they are removed from the view hierarchy.
系统保持一个参考的卸载项目,所以他们不会释放当他们从视图层次结构中删除。
Final and Base Size Classes最终和基本尺寸类
Interface Builder recognizes nine different size classes.
接口生成器识别九个不同大小的类。
Four of these are the Final size classes: Compact-Compact, Compact-Regular, Regular-Compact, and Regular-Regular. The Final classes represent actual size classes displayed on devices.
四个是最后的大小类:紧凑紧凑,紧凑定期,定期紧凑,定期定期。最后类表示设备上显示的实际大小类。
The remaining five are Base size classes: Compact-Any, Regular-Any, Any-Compact, Any-Regular, and Any-Any. These are abstract size classes that represent two or more Final size classes. For example, items installed in the Compact-Any size class appear in both the Compact-Compact and Compact-Regular size views.
其余五个基本大小类:紧凑任何,定期任何,任何紧凑,任何定期,任何。这些是表示两个或多个最终大小类的抽象大小类。例如,在紧凑的任何大小类中安装的项目都出现在紧凑紧凑和紧凑的普通大小视图中。
Anything set in a more specific size class always overrides the more general size classes. Additionally, you must provide a nonambiguous, satisfiable layout for all nine size classes, even the Base size classes. Therefore, it is typically easiest to work from the most general size class to the most specific. Select the default layout for your app, and design this layout in the Any-Any size class. Then modify the other Base or Final size classes as needed.
在更具体的大小类中设置的任何东西总是覆盖更一般的大小类。另外,你必须提供一个无二义的,所有九个班级规模,可满足的布局,即使是基础的班级规模。因此,它通常是最容易的工作,从最一般的大小类,以最具体的。为应用程序选择默认布局,并在任何大小的类中设计该布局。然后根据需要修改其他基础或最终大小类。
Using the Size Class Tool使用大小类工具
Select the size class that you are currently editing using Interface Builder’s Size Class tool. This tool is displayed at the bottom center of the Editor window. By default, Interface Builder starts with the Any-Any size class selected.
使用界面生成器的大小类工具选择当前正在编辑的大小类。此工具将显示在编辑器窗口的底部中心。默认情况下,接口生成器从任何选择的大小类开始。
To switch to a new size class, click the Size Class tool. Interface Builder presents a popover view containing a 3 x 3 grid of size classes. Move your mouse over the grid to change the size class. The grid shows the selected size class’s name at the top and a description of the size class (including the devices and orientations it affects) at the bottom. It also displays a green dot in each size class affected by the current size class.
若要切换到新的大小类别,请单击“大小”类工具。界面生成器提出了一个包含一个3 x 3的网格尺寸弹出视图类。将鼠标移到网格上以更改大小类。网格显示选定的大小类的名称在顶部和描述的大小类(包括设备和它影响的方向)在底部。它也显示在当前大小类影响的每个大小类中的绿点。
Any views or constraints added to the canvas are installed only in the current size class. When deleting items, the behavior varies depending on where and how the items are deleted.
添加到画布上的任何视图或约束只安装在当前大小类中。当删除项目时,行为取决于删除项目的位置和方式。
-
Deleting an item from the canvas or document outline removes it from the project entirely.从画布或文档大纲中删除项目将完全删除该项目。
-
Command-Deleting an item from the canvas or document outline only uninstalls the item from the current size class.命令删除项目从帆布或文档大纲只卸载项目从当前大小类。
-
When a scene has more than one size class, deleting items from anywhere other than the canvas or document outline (for example, selecting and deleting constraints from the Size inspector) uninstalls the item only from the current size class.当一个场景有多个大小类,删除项目以外的其他任何地方的帆布或文档大纲(例如,选择从尺寸检查员删除约束)卸载仅从当前大小类项目。
-
If you have edited only the Any-Any size class, then deleting an item always removes it from the project.如果只编辑任何大小类,则删除项总是从项目中移除它。
If you are editing any size class other than the Any-Any size class, Interface Builder highlights the toolbar at the bottom of the editor window in blue. This makes it obvious when you’re working on a more specific size class.
如果您正在编辑任何大小类,而不是任何大小类,则界面生成器突出显示编辑器窗口底部的工具栏。这使得它明显当你在一个更具体的大小类。
Using the Inspectors利用督察
You can also modify the size-class-specific settings in the inspectors. Anything that supports size-class-specific settings appears in the inspector with a small plus icon beside it.
还可以修改检查人员的大小类特定设置。任何支持大小类特定设置的检查员将在其旁边加上一个小图标。
By default, the inspector sets the value for the Any-Any size class. To set a different value for a more specific size class, click the plus icon to add a new size class. Select the width, and then the height, for the size class you want to add.
默认情况下,检查程序为任意大小的类设置值。若要为更具体的大小类别设置不同的值,请单击“添加”图标以添加新的大小类别。选择要添加的大小类的宽度和高度。
The inspector now shows each size class on its own line—the Any-Any setting is the top line, with the more-specific size classes listed below. You can edit the value of each line independently of the others.
督察现在显示每一个大小类在其自己的行任何设置是最上面的线,与更具体的大小类如下。您可以独立编辑每个行的值。
To remove a custom size class, click the x icon at the beginning of the line.
若要移除自定义大小类别,请单击该行开头的x图标。
For more information on working with size classes in Interface Builder, see Size Classes Design Help.
有关在接口生成器中使用大小类的详细信息,请参阅大小类设计帮助。