I have UIStackView
inside vertical scroll UIScrollView
with all limitations using auto layout. The scroll view fills the supervisor, the stack view fills the scroll view, and various elements are added to the stack view. To make it convenient with Auto Layout and determine the size of the scroll content, you must also specify the width of the stack view. This is done by adding a width constraint in the stack view equal to the scroll width. At this moment, there is nothing ambiguous, it behaves exactly as we would like.
Now, if you want to add margins so that the elements do not stretch to the far left and right edges of the screen, you can change the constant constants of drag and drop in the stack view to insert 15pt on both sides for example. But then you should definitely change the constant constant of equal width to -30. And this works well by inserting scrollable content, while still allowing you to scroll along the far edges of the screen to scroll.
Now comes the iPhone X, and 15pt filling is no longer enough when in the landscape, because the content is placed under the body sensor. Therefore, you need to update this to set the fields to match the fields of the safe area. You really want to use the default fields. You can change the constraint constants of the top and end stack to use the fields of the layout of the view (as for add-ons in the safe area), but this will not work, because your constant of the width constraint is equal to no longer double the number of fields, the fields are dynamic now.
Thus, one way to solve this problem is to create IBOutlet
upper and lower stack restrictions and stack width restrictions, and then programmatically configure them all when changing the layout fields ( viewLayoutMarginsDidChange
). But I wonder if there is a better approach, preferably a solution that works inside Interface Builder, no code required.
source
share