Reputation: 6861
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
}
}
Upvotes: 0
Views: 3838
Reputation: 1130
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.
Upvotes: 0
Reputation: 12023
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
Upvotes: 2
Reputation: 203
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.
Upvotes: 1