1

I'm trying to make a view scrollable in my app.

O follow exactly the steps in tutorial https://www.youtube.com/watch?v=UnQsFlMGDsI .

The main steps I did were:

  • Add a UIscrollView
  • Add a view into UIscrollView (Content View)
  • Create the margin constraints with value 0 (top, left, right and botton) for UIScrollView
  • Create the margin constraints with value 0 (top, left, right and botton) for Content view
  • Create 2 constraints of "equal width" and "equal height" between ContentView and main view
  • ... (Add some text fields)

When I run the app, the scrollView doesn't work

enter image description here

I really can't make it work. I tried many ways to apply a UIScrollView and didn't get it.

2
  • Did you try giving the contentSize ? scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, sizeOfContent);
    – Sreejith
    Aug 21, 2015 at 18:21
  • @Sreejith All tutorial as read it wasn't necessary set it by code. I checked and it seems that the constraint "equal height" make it. I published a video to show what is happening youtube.com/watch?v=59lQZAEq5lM&feature=youtu.be Aug 21, 2015 at 20:21

2 Answers 2

5

As mentioned in the video, the main aim is to automatically adjust the UIScrollView contentSize to the size of the screen or to the size of the content in such way that on smaller devices scrolling is active and on larger devices scrolling is not active because it is not needed.

For this to achieve you've to set proper constraints to the content view so that the height is automatically calculated. From your video its visible that you're not setting the proper constraint to the last UITextFeild (this is important).

You have to give the top as well as the bottom constraint to the last UITextField so that contentView height is automatically calculated.

I have done a sample project which you can check here :
Sample Project

3
  • it was very helpful... The vertical scroll worked. But now I'm getting another problem because the area of scroll view is thin occupying just the half screen. imgur.com/Ow0MXpQ Aug 22, 2015 at 14:58
  • I think I solved it. I just added a constraint of width "Greater than or Equal" with value 290 in first text field. imgur.com/moXY7XK Thank's so much for your help! Aug 22, 2015 at 15:19
  • My pleasure :) Good day.
    – Sreejith
    Aug 22, 2015 at 15:38
0

you can do this for working UIScrollView:

1)add a ViewController

2)put a UIScrollView in it

3)from "Simulated Metric" change size to Freeform. change the height to your desire height

4)add auto layouts to both UIScrollView and View (it's not needed)

5)put your controls in view and add auto layouts to them.

this should work :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.