0

I have UIViewController. It has a UIView with three objects(UILabel, UIImageView, UITextView) inside UIScrollView. When I try scroll vertical nothing happens. I use autolayout. Before I made it without UIView inside UIScrollView but there is an empty space in the bottom.

@IBOutlet weak var scrollView: UIScrollView! {
    didSet {
        scrollView.delegate = self
        scrollView.scrollEnabled = true
        self.scrollView.frame.size = scrollView.contentSize //12
    }
}

enter image description here enter image description here

4
  • what are the values for the scrollView.contentSize... why should it scroll vertically? Commented Jul 5, 2015 at 16:00
  • @jdi If I make self.scrollView.contentSize = CGSizeMake(self.viewV.frame.width, self.view.frame.height) I get the error fatal error: unexpectedly found nil while unwrapping an Optional value Commented Jul 5, 2015 at 16:08
  • try setting values yourself to see: scrollView.frame.size.height = 800. Does it extend it? Commented Jul 5, 2015 at 16:12
  • @jdi No, it doesn't work for me Commented Jul 5, 2015 at 16:16

3 Answers 3

2

if you are using auto layout no need to set the frame of scrollview, give your view which is subview of scrollview height constraint e.g. 800 and set scrollview and outer view width constraint to match the width for each device and set scrollview frame using autolayout, this will start scrolling.

refer this link for further details

Sign up to request clarification or add additional context in comments.

5 Comments

When I made like written in this link I get good scrolling on horizontal but no vertical.
I'm sorry. It was my mistake. I fixed it and it works is well for me. Thank you for your answer!
@Alexsander what was your mistake can you please tell me ... because i am having the same issue
@OsamaBinBashir Hello! I do not remember exactly, but like I did the following. You need to assign the contentSize to the scrollView. Also, if I was doing now, then I probably made this controller with UITableView. Please tell me if it helped you or not?
@OsamaBinBashir for example yourScrollView.contentSize = CGSizeMake(375, 1000) also please look at stackoverflow.com/questions/33715402/… and stackoverflow.com/questions/39772422/…
1

The problem is that you're setting the scroll view's frame size to be equal to the scroll view's content size. A scroll view will only scroll if its content is larger than its frame. Instead, set the scroll view's frame size to match the container view's size, and set the content size's height to the bottom of the text view.

Comments

0

When we are using scrollview with auto layout it little bit confuting but it you see scroll view's behavioral then you will easily get idea about it.

for scrollview set constraint as 0 for four sides. then check out the size of you view (which you added in scrollview) and set it to scrollview content size. for view set equal weight constraint with scrollview width.

I hope it will help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.