title: Autolayout UIScrollView constraints strange behaviour
body: <p>I already read the iOS6 release notes and some of the related topics for Autolayout + UIScrollview here, but I have a strange bug I don't know how to solve.</p>
  
  <p>The view's hierarchy is :</p>
  
  <pre><code>- View
  -- UIScrollView
  ---- UIImageView
  ---- UILabel
  </code></pre>
  
  <p>I added the elements in the view through Interface Builder, with Autolayout ON and kept the default constraints.</p>
  
  <p>My label has a dynamic text and its height is expendable (number of lines = 0 configured in IB).
  I want that the scroll view adapts automatically to the height of the image view + the label.</p>
  
  <p>Here is the code for the associated view controller class:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
  
      self.scrollView.translatesAutoresizingMaskIntoConstraints = NO;
      self.imageView.translatesAutoresizingMaskIntoConstraints = NO;
      self.label.translatesAutoresizingMaskIntoConstraints = NO;
  
      self.imageView.image = [UIImage imageNamed:@"image.png"];
  
      self.label.text = @"Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text Text text END";
      [self.label sizeToFit];
  
      NSDictionary *viewsDictionnary = NSDictionaryOfVariableBindings(scrollView, imageView, label);
      [self.scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView]-20-[label]-10-|" options:0 metrics:0 views:viewsDictionnary]];
  
      self.imageView.userInteractionEnabled = YES;
      [self.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)]];
  }
  
  - (void)tap
  {
      [self.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View2"] animated:YES];
  }
  </code></pre>
  
  <p>As you can see, I'm adding a vertical constraint for the scroll view. This seems to works well but I have the following message in the console:</p>
  
  <blockquote>
    <p>2013-03-26 16:24:49.072 test[34704:11303] Unable to simultaneously
    satisfy constraints.  Probably at least one of the constraints in the
    following list is one you don't want. Try this: (1) look at each
    constraint and try to figure out which you don't expect; (2) find the
    code that added the unwanted constraint or constraints and fix it.
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you
    don't understand, refer to the documentation for the UIView property
    translatesAutoresizingMaskIntoConstraints)  (
        "",
        "" )</p>
    
    <p>Will attempt to recover by breaking constraint 
    </p>
  </blockquote>
  
  <p>And now the concrete bug:
  If I scroll to the down, then I click on the image to go to the second view, and click back to return to the current view, the scroll view will starts from the precedent position as it was the top of the view. And I won't be able to scroll to see the up of the view.</p>
  
  <p>I'm sorry I don't have enough reputation to post images, but you can download the sample project here to reproduce the bug : <a href="https://docs.google.com/file/d/0B-sCDWMvn-KGS19sUkZnUFdWWTg/edit?usp=sharing" rel="nofollow noreferrer">https://docs.google.com/file/d/0B-sCDWMvn-KGS19sUkZnUFdWWTg/edit?usp=sharing</a></p>
  
  <p>Thanks for the help,
  Lukas</p>
  
  <p>EDIT
  Workaround for the bug here: <a href="https://stackoverflow.com/questions/15345522/uiscrollview-wrong-offset-with-auto-layout/15350131#15350131">UIScrollView wrong offset with Auto Layout</a></p>