android上的view的类叫View,
以下是它的class overview,
This class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). The ViewGroup
subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.
根据以上说明,可以看出,ViewGroup类才能添加子view,View类本身不提供添加子view的功能。
ios上的view的类叫UIView,
以下是它的class overview,
The UIView
class defines a rectangular area on the screen and the interfaces for managing the content in that area. At runtime, a view object handles the rendering of any content in its area and also handles any interactions with that content. The UIView
class itself provides basic behavior for filling its rectangular area with a background color. More sophisticated content can be presented by subclassing UIView
and implementing the necessary drawing and event-handling code yourself. The UIKit framework also includes a set of standard subclasses that range from simple buttons to complex tables and can be used as-is. For example, a UILabel
object draws a text string and a UIImageView
object draws an image.
Because view objects are the main way your application interacts with the user, they have a number of responsibilities. Here are just a few:
-
Drawing and animation
Views draw content in their rectangular area using technologies such as UIKit, Core Graphics, and OpenGL ES.
Some view properties can be animated to new values.
-
Layout and subview management
A view may contain zero or more subviews.
Each view defines its own default resizing behavior in relation to its parent view.
A view can define the size and position of its subviews as needed.
-
Event handling
A view is a responder and can handle touch events and other events defined by the
UIResponder
class.Views can use the
addGestureRecognizer:
method to install gesture recognizers to handle common gestures.
Views can embed other views and create sophisticated visual hierarchies. This creates a parent-child relationship between the view being embedded (known as the subview) and the parent view doing the embedding (known as the superview). Normally, a subview’s visible area is not clipped to the bounds of its superview, but in iOS you can use the clipsToBounds
property to alter that behavior. A parent view may contain any number of subviews but each subview has only one superview, which is responsible for positioning its subviews appropriately.
根据以上说明,iso的view具有添加subView的功能。
仔细对比阅读以上overview,可以更加明确它们之间的区别。