Embedding a child view controller inside a scroll view results in that view's intrinsic content size not being respected/used

Originator:armadsen
Number:rdar://24513193 Date Originated:04-Feb-2016 04:00 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Version 7.2.1 (7C1002)
Classification:Other Bug Reproducible:Always
 
Summary:
When a UIScrollView's content view is a container view with an embed segue to embed a child view controller whose view is a custom UIView subclass ("ItemView"), the child VC's view's intrinsicContentSize() method is never called, and the view is sized such that it is invisible (zero size in at least one dimension).

This behavior is not seen if an ItemView instance is placed directly inside the scroll view instead of using an embed segue to embed its  view controller.

Steps to Reproduce:
1. Add a UIScrollView and place it in an empty view controller's view.
2. Constrain all 4 sides to its superview such that it fills the screen.
3. Drag a container view into the scroll view.
4. Constrain the container view's 4 sides to its superview (the scroll view)
5. Using an embed segue, embed a view controller in the container view. The view controller's view should be a subclass of UIView that overrides intrinsicContentSize().
6. Run the app.

Expected Results:

The embedded view shows up in the scroll view at a size equal to its intrinsic content size, and can be scrolled if this size is bigger than the scroll view.

Actual Results:

The embedded view is invisible, and its intrinsicContentSize() method is never called. Inspection reveals that its size is zero in at least one dimension.

Regression:

If the embedded view is put directly inside the scroll view (sans its own view controller) instead of using an embed segue, intrinsicContentSize() is called and the view is visible and sized as expected.

Another possible workaround is to make the embedding container view a subclass of UIView whose intrinsicContentSize() method returns its subview's intrinsic content size (see ContainerView in the attached project).

Notes:

A very simple demo project that shows this problem can be found here: https://www.dropbox.com/s/ic3qt5k014a9jzk/ScrollViewTest.zip?dl=1 It contains a storyboard with two scenes, and a single UIView subclass (DummyView) whose intrinsicContentSize() method returns (1000, 1000). In both scenes, DummyView has been set to have a greenish background color to make it obviously visible, while the scroll view has a different background color. 

In the first scene, the broken scenario above is implemented. Running with this scene's VC set as the initial view controller produces a magenta screen indicating that only the scroll view is visible, and its child green DummyView is not. Additionally a breakpoint in intrinsicContentSize() shows that it is never called.

In the second scene, a DummyView instance is placed directly inside a scroll view instead of via embedding a view controller. Running with this scene's VC set to be the initial VC produces a green screen indicating that the DummyView is sized appropriately (or at least not zero) and is visible. Additionally a breakpoint in intrinsicContentSize() shows that it is called.

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!