0

I have a very simple view. It is just a view with a UISCrollView and an UIImageView below. Inside the UIScrollView I have a very large UIImageView. Now I need to set the UIScrollview it's contentsize using autolayout.

But I can't figure it out how I can do that ? Here is how my storyboard looks like.

enter image description here

I've tried to put the UIImageView inside a UIView and make that UIView the only child of de UIScrollView but that is also not working. Turning off autloayout is not an option because all my other views are using autolayout

Any help on this ?

Vizllx
  • 9,135
  • 1
  • 41
  • 79
Steaphann
  • 2,797
  • 6
  • 50
  • 109
  • 1
    Try this link:- http://stackoverflow.com/questions/13499467/uiscrollview-doesnt-use-autolayout-constraints – Vizllx Nov 12 '13 at 07:56

3 Answers3

0

You should set many constraints to make it working in the right way. If I understand corretly, you want something similar:

View
----------------------------------
| ScrollView                     |
|--------------------------------|
||                              ||
||                              ||
||                              ||
|--------------------------------|
|ImageView                       |
|--------------------------------|
||                              ||
|--------------------------------|
----------------------------------

In this case you should set the constraints to be the top of the Scrollview exactly the View's top. The ImageView's top is the ScrollView's bottom, the ImageView's bottom is the View's bottom. And inside the ScrollView to things similarly. If you will have each needed constraint it will work.

Dave
  • 1,081
  • 6
  • 10
0

I use bordering view by creating such constraints in scrollView for example:

H:|[borderView(400)]|
V:|[borderView(600)]|

May be you can use your's UIImageView as bordering view.

Cy-4AH
  • 4,370
  • 2
  • 15
  • 22
0

The contentSize of a UIScrollView can be implicitly set through the NSLayoutConstraints within the UIScrollView.

The way this would be done (If you wanted the image view to fit snugly in the UIScrollView) is:

UIImageView *imageView = ...
UIScrollView *scrollView = ...
NSDictionary *viewsDictionary = @{@"imageView" : imageView};
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView]|"
                                                                   options:kNilOptions
                                                                   metrics:nil
                                                                     views:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView]|"
                                                                   options:kNilOptions
                                                                   metrics:nil
                                                                     views:viewsDictionary]];

The contentSize would be equal to the size of the UIImageView.

Obviously to place the UIScrollView that would just be the same as placing any other view in it's subview.

Infinity James
  • 4,667
  • 5
  • 23
  • 36