Question

What is the effect of having a UIView act as a child of another UIView in the scoreboard?

Using AVCam as an example, in the storyboard of the project, the components are layered out as following:

enter image description here

Observe that the 3 Button components act as children of “Cam Preview View”.

I’ve made an experiment and managed to get them to be children of “View”. This does not break any UIButton outlet functionality that I’ve managed to notice.

enter image description here

Was it helpful?

Solution

This is a design time choice by the developer. This changes how the controls can be moved by the constraints or other layout controls like springs and strut). Moving them around will not break any wired outlets however can introduce logical errors.

That said it's possible that there is no significant effect for this demo code.

OTHER TIPS

In the first image you posted, those buttons are added as subviews of the Cam Preview View. It is the same as saying

[camPreviewView addSubview:button];

In the second image instead of the buttons subviews of the Cam Preview View, they are subviews of the View at the top of the hierarchy.

This is a design choice made by the developer. Clearly s/he wanted a view with three buttons contained inside as subviews. That way, you can move the Camera Preview View around and the buttons stay in their relative locations within the view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top