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

Alexander Khitev
  • 5,168
  • 13
  • 45
  • 96

3 Answers3

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

Suhit Patil
  • 10,286
  • 2
  • 42
  • 54
  • When I made like written in this link I get good scrolling on horizontal but no vertical. – Alexander Khitev Jul 05 '15 at 17:45
  • I'm sorry. It was my mistake. I fixed it and it works is well for me. Thank you for your answer! – Alexander Khitev Jul 06 '15 at 07:42
  • @Alexsander what was your mistake can you please tell me ... because i am having the same issue – osama Mar 24 '17 at 16:46
  • @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? – Alexander Khitev Mar 24 '17 at 18:35
  • @OsamaBinBashir for example yourScrollView.contentSize = CGSizeMake(375, 1000) also please look at http://stackoverflow.com/questions/33715402/swift-how-to-set-uiscrollview-contentsize-height-to-height-of-contents and http://stackoverflow.com/questions/39772422/how-to-set-scrollview-content-size-in-swift-3-0 – Alexander Khitev Mar 24 '17 at 18:36
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.

Dklionsk
  • 203
  • 1
  • 5
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.

Pravin Tate
  • 1,125
  • 8
  • 18