Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make uiscrollview only vertical scrolling for ios?

I'm trying to make layout inside scrollview using this one tutorial link

And get the following result link

It will be appreciated for any advices or tutorial links. It needs only vertical scrolling

like image 436
Alexey Zakevich Avatar asked May 27 '15 13:05

Alexey Zakevich


People also ask

What is scroll view in IOS?

The scroll view displays its content within the scrollable content region. As the user performs platform-appropriate scroll gestures, the scroll view adjusts what portion of the underlying content is visible. ScrollView can scroll horizontally, vertically, or both, but does not provide zooming functionality.

How can I make my layout scroll vertically in Android?

Vertical scroll view going to scroll its child view in Vertical direction so we have created Linear layout as a child for Vertical scroll view and added child for linear layout.

What is scroll view SwiftUI?

SwiftUI's ScrollView allows us to create scrolling containers of views relatively easily, because it automatically sizes itself to fit the content we place inside it and also automatically adds extra insets to avoid the safe area.


2 Answers

Have you set up the "ContentView" width to match with the scroll view width? I had the same problem and I fixed with "Equal Widths".

"Equal Widths" will tell to your "ContentView" to use the same width of the "Scroll View", which should be fitting the screen if you have set up the constrain properly.

You can do this easily on the storyboard.

  1. Drag and drop, with right click (important!!!), from "ContentView" to "ScrollView"

  2. Release the click, you will be prompted with a menu, select "Equal Widths".

    Prompted menu

This should fix your problem using the scrollview with AutoLayout from Storyboard editor.

You can find a full tutorial how to use ScrollView with Autolayout and Storyboard here.

I hope this is useful for you :)

like image 101
Jesuslg123 Avatar answered Sep 30 '22 11:09

Jesuslg123


This is because scroll view have no idea where your content should end.

But when at least one item inside your scroll view has its "trailing space" constraint attached to a view outside the scroll view (usually a view the scroll view is sitting in or some other view of a higher level, which "knows" its width) - the scroll view will automatically get an idea about your wanted width and won't scroll horizontally (unless that trailing constraint implies having your content outside the screen).

Better if all items inside scroll view have their "trailing space" constraints connected either to each other or to a view outside the scroll view. But not the scroll view itself.

No additional code or extra constraints needed for this to work.

like image 32
Vitalii Avatar answered Sep 30 '22 12:09

Vitalii