iOS: Autolayout causing UIScrollView to not scroll

I have set up a UIScrollView with which I want to display 12 images (only 8 fit on screen) laid out horizontally. In the following image you can see the problem I’m having (which makes my scroll view not scroll), my constraints and the UIScrollView which I have added on storyboard:

Screenshot of storyboard showing constraints

  • Setting constraints to UIScrollView
  • How do I reset specific size class data on a storyboard in Xcode6?
  • AutoLayout with hidden UIViews?
  • iOS8: Auto-layout and Gradient
  • Inequality Constraint Ambiguity
  • How-to suppress constraint and layout warnings in Xcode 5 on a storyboard?
  • I have called the following method on -(void)viewDidLoad, where I “set up”my scrollview (itemList is my scroll view property and itemNames a array with the images’names):

    - (void)setupHorizontalScrollView
        self.itemList.delegate = self;
        [self.itemList setTranslatesAutoresizingMaskIntoConstraints:NO];
        [self.itemList setBackgroundColor:[UIColor blackColor]];
        [self.itemList setCanCancelContentTouches:NO];
        self.itemList.indicatorStyle = UIScrollViewIndicatorStyleWhite;
        self.itemList.clipsToBounds = NO;
        self.itemList.scrollEnabled = YES;
        self.itemList.pagingEnabled = NO;
        NSInteger tot=0;
        CGFloat cx = 0;
        for (; ; tot++) {
            if (tot==12) {
            UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[self.itemNames objectAtIndex:tot]]];
            CGRect rect = imageView.frame;
            rect.size.height = 40;
            rect.size.width = 40;
            rect.origin.x = cx;
            rect.origin.y = 0;
            imageView.frame = rect;
            [self.itemList addSubview:imageView];
            cx += imageView.frame.size.width;
        [self.itemList setContentSize:CGSizeMake(cx, [self.itemList bounds].size.height)];

    I have added the [self.itemList setTranslatesAutoresizingMaskIntoConstraints:NO]; because I saw this suggestion on other posts, but it doesn’t work with or without it. The only way it works is if I uncheck use AutoLayout on the storyboard, but that moves the UIImageViewI use to look as a navigation bar to the bottom of the screen.
    I don’t know what to do anymore, any help is appreciated 🙂

    3 Solutions Collect From Internet About “iOS: Autolayout causing UIScrollView to not scroll”

    Two Solutions:

    1. Create different constraints that can be satisfied simultaneously (you will have to edit). I think the problem is your bottom space and top space constraints are mutually exclusive. please remove one and try again. IF this is difficult for you, try adding another UIView to contain the UIScrollView to help manage your constraints, it might seem odd at first, but sometimes adding another view to contain your view actually makes it simpler at each level.

    2. Turn off Autolayout, and change the autoresize masks of your UIImageView to be what you wish.

    Try to set your scrollView’s Content size int “viewDidLayoutSubviews” method with keeping the autolayouts set.

      [self.itemList setContentSize:CGSizeMake(required_width, required_height)];

    Insert: [scrollView setContentSize:CGSizeMake(x,y)]; in the following method: