Autolayout Regression: Pinning child controller's view to top layout guide provides different results depending on container view position
| Originator: | Vytis | ||
| Number: | rdar://18582012 | Date Originated: | 08-Oct-2014 |
| Status: | Behaves correctly | Resolved: | YES |
| Product: | iOS SDK | Product Version: | iOS 8.0.2 [12A405] |
| Classification: | Other Bug | Reproducible: | Always |
Summary: The issue is reproducible when a child view controller contains a single subview that is pinned to superview in all directions. The subview is then incorrectly resized if the container view in the parent view controller is covered by the navigation bar. Changing the constraints for the subview to be vertically centered with fixed height fixes the problem. This issue doesn't happen on iOS 7.1.2 so it seems to be a regression. Steps to Reproduce: The steps were done with a standard 'Single View Application' project with size classes turned off in MainStoryboard and deployment target set to iOS 7.0. 1. Add an empty UIViewController embedded in an UINavigationController 2. Set UINavigationController's navigation bar to be translucent. 3. Place a container view so that it is partly covered by the navigation bar (i.e. at y = 10). 3a. To see results better set background color of the child view controller's root view to red. 4. Add a single subview in the child view controller. Set background color to green. 5. Add constraints for the subview in all directions with constant = 0 and without using margins. Expected Results: The subview in the child controller should be of the same size as the container view, i.e. be visible from behind the navigation bar. In our case we should see a green tint of the navigation bar. This is what happens on iOS 7.1.2 Actual Results: The subview is resized incorrectly as it doesn't get covered by the navigation bar. In our case we see that root view of the child controller becomes visible and the navigation bar is tinted red Version: iOS 8.0.2 [12A405] Notes: In the attached sample project there are two container views. The left one shows the issue, while the right one has different constraints and works as expected. On iOS 7.1.2 both of these container views appear identical Configuration: iPhone 5c 32GB Attachments: 'ExampleProject.zip' was successfully uploaded.
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!
Apple response
The behavior is because of a fix to how container view controllers handle the layout guides in iOS8. On iOS7 the layout guide length of the container was improperly ignored. Now that it’s not being ignored on iOS8, you’re getting a length for your layout guide that you didn’t previously.
Because you want your view under the navigation bar, you want to contrain the top of your view to the top of your superview (not to the bottom of the layout guide).