Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

( iOS ) What is superview and what is subviews

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?

like image 305
Edward Anthony Avatar asked Oct 29 '12 14:10

Edward Anthony


People also ask

What is SuperView in IOS?

The superview is the immediate ancestor of the current view. The value of this property is nil when the view is not installed in a view hierarchy. To set the value of this property, use the addSubview(_:) method to embed the current view inside another view.

What is a SuperView?

Answer. SuperView allows you to capture an immersive wide angle perspective. What this mode does is it takes a 4:3 aspect ratio and dynamically stretches it to a 16:9 aspect ratio.

What are subviews?

A Subview is any View that is the child of another View. You can create a hierarchy with any number of Subviews. For example, the top level View you can have is the My Network View. Beneath this you might want to create a View called Device Types.

What is a receiver in Swift?

"receiver" is a throwback to the days of objective-c when "messages" were sent to "objects". So us old people (hah) used to call [someView addSubview:anotherView] instead of someView. addSubview(anotherView) . In that scenario, "someView" is the receiver because it's RECEIVING the "addSubview" message.


2 Answers

A superview is a view that holds other views over it and subviews are the views being held/added over a View.

Let's assume we have a view named MyView, which holds a UIButton (named loginButton) over it. Here MyView is considered a superview for loginButton and loginButton is considered a subview of MyView.

For more, you should start from here

As per the provided code snippet.

[self.view addSubview:self.frontView];

Hence view (Controller's view) is a superview and frontView is a subview

like image 163
Kamar Shad Avatar answered Sep 30 '22 16:09

Kamar Shad


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

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.

like image 21
Ivan Surzhenko Avatar answered Sep 30 '22 16:09

Ivan Surzhenko