iOS中场景和视图之间的区别

时间:2021-09-16 15:15:41

I'm new to iOS I'm having trouble understanding the difference between scene and a view. Unfortunately Apple's documentation isn't helping me. I read that a scene is what you see on the screen. But isn't that what a view is? Are these two interchangeable terms? If not what are the differences, both functionality and best practice? How does a ViewController come into play for both of these?

我是iOS新手我无法理解场景和视图之间的区别。不幸的是Apple的文档没有帮助我。我看到一个场景就是你在屏幕上看到的。但这不是一个观点吗?这两个可互换的术语是?如果没有,那么功能和最佳实践有何区别? ViewController如何为这两者发挥作用?

Any explanations or links are much appreciated.

任何解释或链接都非常感谢。

1 个解决方案

#1


13  

In simple terms:

简单来说:

View

A UIView is a rectangular area that is displayed on the screen.

UIView是一个显示在屏幕上的矩形区域。

ViewController

A collection of Views displayed on the screen at the moment.

此时屏幕上显示的视图集合。

In the following image, blue area and yellow area are Views, whereas the entire screen is a ViewController.

在下图中,蓝色区域和黄色区域是视图,而整个屏幕是ViewController。

iOS中场景和视图之间的区别

Scene

A ViewController which is a part of a specific sequence.

ViewController,它是特定序列的一部分。

iOS中场景和视图之间的区别

However, the technical definitions are a little different:

但是,技术定义略有不同:

UIView

A UIIView is a wrapper to CALayer. It holds an array of subviews which implies that it's a collection of views by itself. You can imagine this as a tree structure.

UIIView是CALayer的包装器。它包含一系列子视图,这意味着它本身就是一组视图。您可以将其想象为树结构。

ViewController

A ViewController is a controller which holds a reference to the root view. This way, you can traverse the leaf node or any subview from the controller.

ViewController是一个控制器,它保存对根视图的引用。这样,您可以从控制器遍历叶节点或任何子视图。

Scene

"Scene" is another term for a ViewController in one context of storyboard.

“场景”是故事板的一个上下文中ViewController的另一个术语。

#1


13  

In simple terms:

简单来说:

View

A UIView is a rectangular area that is displayed on the screen.

UIView是一个显示在屏幕上的矩形区域。

ViewController

A collection of Views displayed on the screen at the moment.

此时屏幕上显示的视图集合。

In the following image, blue area and yellow area are Views, whereas the entire screen is a ViewController.

在下图中,蓝色区域和黄色区域是视图,而整个屏幕是ViewController。

iOS中场景和视图之间的区别

Scene

A ViewController which is a part of a specific sequence.

ViewController,它是特定序列的一部分。

iOS中场景和视图之间的区别

However, the technical definitions are a little different:

但是,技术定义略有不同:

UIView

A UIIView is a wrapper to CALayer. It holds an array of subviews which implies that it's a collection of views by itself. You can imagine this as a tree structure.

UIIView是CALayer的包装器。它包含一系列子视图,这意味着它本身就是一组视图。您可以将其想象为树结构。

ViewController

A ViewController is a controller which holds a reference to the root view. This way, you can traverse the leaf node or any subview from the controller.

ViewController是一个控制器,它保存对根视图的引用。这样,您可以从控制器遍历叶节点或任何子视图。

Scene

"Scene" is another term for a ViewController in one context of storyboard.

“场景”是故事板的一个上下文中ViewController的另一个术语。