Auto Layout - UIScrollView Unexpected Behavior

Number:rdar://13648069 Date Originated:13-Apr-2013 04:10 PM
Status:Duplicate Resolved:16-Apr-2013 07:45 PM
Product:iPhone SDK Product Version:6.1.3
Classification:Serious Bug Reproducible:Always
Using what the 6.0 release notes call a "pure constraints" approach, UIScrollView defines its content size through the layout constraints of subviews tying to the superview.

e.g. The constraints @"H:|-[someView(280)]-|" when applied to a scroll view will cause the content size to be 320pts wide

This is does work, but when navigating away from a view controller and then back to the same instance the scroll view's content area is drawn incorrectly.

Steps to Reproduce:

1. Setup a view controller that manages a scroll view in code or storyboard following this idea from the iOS 6.0 SDK Release Notes:

--- CUT / PASTE ---

UIScrollView *scrollView = [[UIScrollView alloc] init];
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setImage:[UIImage imageNamed:"MyReallyBigImage"]];
[self.view addSubview:scrollView];
[scrollView addSubview:imageView];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
imageView.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(scrollView,imageView);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[scrollView]|" options:0 metrics: 0 viewsDictionary:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[scrollView]|" options:0 metrics: 0 viewsDictionary:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView]|" options:0 metrics: 0 viewsDictionary:viewsDictionary]];
[scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[imageView]|" options:0 metrics: 0 viewsDictionary:viewsDictionary]];

--- CUT / PASTE ---

2. Install this view controller ("image view controller") into a tab bar controller
3. Build and run
4. Move the content offset of the image view controller's scroll view to the maximum allowable distance from (0, 0)
5. Tap on another tab in the tab bar controller
6. Tap on the tab to return to the image view controller

Expected Results:

7. Expect content offset and content view to look as they did before navigating away

Actual Results:

7. Content offset reports same value, however on screen content view is drawn at incorrect location



Sample project attached


16-Apr-2013 07:45 PM Apple Developer Bug Reporting Team :

This bug has been closed as Duplicate. The issue is being tracked under the Bug ID listed below in the Related Problem section of your bug report. To check the status of the original bug report, please visit the Related Problem section of the Problem Detail view of your closed duplicate bug.

For further information on the status of the original bug report, please update your report directly and we will provide you with any available information.

duplicate of 12523345 Open

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!