Autolayout + Scrollview Subviews + Scrollview Content Offset = Sad View

Originator:designatednerd
Number:rdar://13942147 Date Originated:5/20/13
Status:Duplicate Resolved:Duplicate
Product:iOS SDK Product Version:iOS 6.0+
Classification:UI/Usability Reproducible:Always
 
Summary:
When navigating away from a view with a long scrollview with direct subviews of that scrollview, then returning to it, the view will offset its contents by 1/2 the contentOffset property on Retina devices, and the full contentOffset on non-retina devices. 

Steps to Reproduce: 
- Create a view using autolayout with a scrollview that is longer than the screen. 
- Scroll down a bit. 
- Move to a new view controller. 
- Go back to initial view controller, note that your views are all now offset by 1/2 the amount 

Expected Results:
- Returning to a view will not cause its contents to offset even if using direct subviews of a scrollview

Actual Results:
- Contents are offset in an unacceptable and unexpected fashion. 


Regression:
This behavior was not present prior to the introduction of AutoLayout. 

Notes:
This behavior does not occur if using a containing UIView for your scrollView Subviews.

This is happening somewhere between when viewWillAppear and viewDidLayoutSubviews are called in the ViewController. If we save the content offset  to a property in viewWillAppear: then reset it to CGPointZero, then in viewDidLayoutSubviews put it back to the previous offset, the view behaves as expected. 

I included a sample project that reproduces this behavior and has a block of code you can uncomment to see the workaround. [Openradar note: email designated nerd at gmail dot com if you want a copy]


[NOTE: 5/28/13: Just received an email from Apple informing me this is being closed as a dupe and is being tracked under bug #12523345 - file more dupes if you want them to fix it!]

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com 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!