How to make this scroll view scrollable? - swift

I'm trying to add a horizontal scroll view to my view controller, but when I run the app I can't scroll. Here's an image:
How should I solve it?

The important thing here is how the constraints of the scroll view and its inner views are set.
You should first set constraint of the scroll view as you would do with another view, once this is done correctly it should have an x and y positions and also would be capable of know width and height.
After that you should set the constraints for inner views, making them push the boundaries of the container (the scroll view). So imagine you have 3 inner views you want to be set vertically:
The first one should have a top constraint to its container (scroll view), and a bottom to the second inner view.
The second one should have a bottom constraint to the third one.
The third one should have a bottom constraint to its container (scroll view).
This should satisfy all the calculation needs by AutoLayout.

Related

Make UITableView ignore Safe Area

I have a TableView inside a ViewController.
I made the TableView stretch to the View SuperMargings (with constraints) and disabled all SafeArea Inset options but my TableView is still under the SafeArea when I run my project.
How can I make my TableView go full height on iPhones with notch?
If you have already pinned tableView to it's superview(not to safeArea) with constraints but tableView still respects safeArea there is property contentInsetAdjustmentBehavior in UIScrollView(UITableView is subclass of UIScrollView as we know) since iOS 11.
This property is UIScrollView.ContentInsetAdjustmentBehavior enum with 4 options.
You need to set .never to contentInsetAdjustmentBehavior.
What works with any view is to associate the bottom constraint of the table view to the bottom anchor of the root (or parent) view (instead of the SafeArea).
This can be done in the storyboard editor double clicking on the constraint in the right inspector and changing the first item anchor from SafeArea to Superview (or any wanted view).
You can then set the edge insets at will if needed (to avoid content remain partially hidden behind the rounded frame corners or the notch if applying the same procedure to the top anchor)

How to make view controller expand to fit layout on smaller screens?

I am working on adding constraints to my view. I have everything perfectly laid out for the iPhone X and it looks great, but I would like my view to expand/scroll to accommodate smaller screens sizes. How can I transform my current view to scroll only if the screen size is not as tall as the iPhone X? ideally with as little reconfiguring as possible.
I follow this approach.
Put all your UI components inside a UIView say it ContainerView.
Now put ContainerView inside a UIScrollView.
Now select ContainerView, add constraints to make width and height equal as of scroll view.
Add a constraint of height on ContainerView. Set its relation as "Greater Than or Equal". Set constant value equal to the height which you want.
Set priority of equal height constraint to High.

StackView not appearing correct on all screen sizes

I have a ViewController that contains a Stack View. In this Stack View there are 3 more Stack Views. The first contains 3 labels, the second contains more Stack Views with buttons and labels, and the third contains 2 buttons and a label. And at the bottom, there is a button. The layout is fine on screen sizes from 4,7" and bigger. But when the screen size is smaller, it cuts out the top Stack View. I have tried to set constraints on leading, trailing, top and bottom in different variations (with and without top and bottom constraints) But I can't make it work properly. I have attached screenshots of the different screen types.
EDIT* Depending on the selection from the previous ViewController, the middle Stack View(the one with the check boxes) can be isHidden When its hidden, the view is correct.
Generally you don't set height on UIStackView. They are dependent on it's content. This will cause your stackview to get out of the screen height. Have you used the view hierarchy? If you want to cover the small sized phones you could put your main stackView inside a scrollView to still be able to see all content.
It's a bit difficult to diagnose what's happening without seeing the constraints you apply to the views, however I'll recommend you some things that may help:
Set the space between views using size classes so you can set the right one depending on the screen size and avoid the overlap with the below views.
In case you are doing it, don't set a height constraint for any stackView.
To align the top StackView I would use not only a top constraint to the top bar (of type greater than or equal) but also a vertical center constraint with a right multiplier (with a high priority). In this way you ensure the top stack view is aligned vertically in proportion to the screen size and with the top constraint you ensure the stackView doesn't hide below the top bar.
Make sure you are hiding the right stackView.

Position in relative to parent view with auto layout in Objective C

I have a UITextView that I want always to be 10px from the bottom of it's parent view (the scrollview). Problem is that I don't know how to tell the auto layout that it is supposed to do Bottom Space To: Parentview, instead of superview.
This is what I have now:
Update:
I need something similar to this:
I got that from here - http://www.techotopia.com/index.php/Working_with_iOS_6_Auto_Layout_Constraints_in_Interface_Builder - I want to have a UITextView in relation to the view it is in.
Click the gear for the “Bottom space to: superview” constraint and edit it. Set the constant to 10.
UPDATE
I've investigated this a bit and decided there's a bug in autolayout. Specifically, autolayout acts as if the size of the scroll view is 0⨉0 instead of its actual size.
Because of tis, if your text view has top-space-to-superview constraint and a bottom-space-to-superview constraint, only the top constraint will be honored. (I tried setting the priority of the top constraint to 1, the minimum, and the bottom constraint was still ignored.) If you delete the top constraint in viewDidLoad, the bottom constraint will be honored, but the text view will be laid out as if the scroll view's height is zero. This means that the text view's bottom edge will be 10 points above the top edge of the scroll view.
This happens in my testing with both a storyboard and a xib.

Horizontal Scrolling when Scrollview inside Scrollview

I have two horizontal paging scroll views where a one is smaller and a subview of the the other. Is there a setup that consistently allows a horizontal drag to move the outer scroll view when there is no more paging to do in the inner scroll view?
Apparently you have to turn off the rubberbanding in the inner scroll view for this to work properly.