各位iOS开发大佬们好:
我是一名Swift+SwiftUI栈的iOS小白,目前还在上大三,最近准备实习,面试的过程中发现现在大公司很多还在用OC + UIKit的技术栈,OC我还在考虑要不要学,目前想先把UIKit学完,这是我在官网学习UIKit英文文档时摘录的本人认为的重点,如果你们也觉得对你们有用的话欢迎持续关注,我大概一天更一节,有事除外。格式什么的我也就不做了,翻译都是我自己翻译的,哪里不对欢迎在评论区指正,感谢各位大佬支持
今天2021年12月11日
这一章叫做Overview
The Role of View Controllers
View controller(以下尊称为VC)是app的基础,每个app都至少有一个VC,VC管理着UI的本身,UI与数据,UI与UI之间的变化
The UIViewController class defines the methods and properties for managing your views, handling events, transitioning from one view controller to another, and coordinating with other parts of your app. You subclass UIViewController (or one of its subclasses) and add the custom code you need to implement your app’s behavior.
UIViewController类定义了管理视图,处理事件,转换,与其他视图协调的方法和属性,通过继承UIViewController类或其子类来自定义实现app需要的行为
There are two types of view controllers:
Content view controllers manage a discrete piece of your app’s content and are the main type of view controller that you create.
Container view controllers collect information from other view controllers (known as child view controllers) and present it in a way that facilitates navigation or presents the content of those view controllers differently.
Most apps are a mixture of both types of view controllers.
两类VC:
内容VC管理app中的独立内容
容器VC从其他VC(一般是子VC)收集信息,并以方便导航或以不同方式显示这些视图控制器内容的方式呈现信息。
VC最重要的职责就是管理视图层级
It is common practice to use outlets to access other views in your view controller’s view hierarchy. Because a view controller manages the content of all its views, an outlet is a property of an object that references another object. outlets let you store references to the views that you need.
通过outlets可以在视图层级中访问其他视图,outlets就是一个储存了其他对象引用的对象属性
A content view controller manages all of its views by itself. A container view controller manages its own views plus the root views from one or more of its child view controllers. The container does not manage the content of its children. It manages only the root view, sizing and placing it according to the container’s design.
内容VC管理了它视图层级下的所有视图,包括其子VC下的所有视图,容器VC就不鸟它的子VC了,根据设计设置尺寸和位置
A view controller