xcode ( iOS ) 什么是超级视图,什么是子视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13123306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:57:46  来源:igfitidea点击:

( iOS ) What is superview and what is subviews

iphoneiosxcodeviewobjective-c++

提问by Edward Anthony

What is superview and what is subviews?

什么是超级视图,什么是子视图?

When I add this code:

当我添加此代码时:

[self.view addSubview:self.frontView];
// what does that mean ?

And...

和...

@property (nonatomic, strong) IBOutlet UIImageView *frontView;
[self.frontView superview] != nil // means ?

what is in superview?

什么是超级视图?

回答by Kamar Shad

A superviewis a view which holds other views over it. subviewsare the views being held/added over a 'View'.

Asuperview是一个视图,它持有其他视图。subviews是在“视图”上持有/添加的视图。

Lets say you have a view called MyView, which has a UIButton(loginButton) over it. In this case, MyViewis a superviewfor loginButtonand loginButtonis a subview of MyView.

假设您有一个名为 的视图MyView,上面有一个UIButton(loginButton)。在这种情况下,MyViewsuperviewforloginButton并且loginButton是 的子视图MyView

For more ,you should start from here

更多,你应该从这里开始

回答by Ivan Surzhenko

"superview" means the view which holds the current one. "subviews" means the views which are holding by the curent view.

“superview”是指保存当前视图的视图。“子视图”是指当前视图所持有的视图。

For example, you have a view (will call it as MyView) which include a button. Button is a view too (UIButton is a kind of view). So, MyView is superview for the button. Button is a subview for MyView.

例如,您有一个包含按钮的视图(将其称为 MyView)。Button 也是一个视图(UIButton 是一种视图)。所以,MyView 是按钮的超级视图。Button 是 MyView 的子视图。

回答by abhishekkharwar

subview is childview ( which is added on any view)

子视图是子视图(添加到任何视图上)

superview is parentview (on which subview is added)

超级视图是父视图(在其上添加子视图)