Auto Layout fails when UINavigationController is added as a child ViewController if `scrollViewDidScroll:` calls `topLayoutGuide`
| Originator: | RichWChan | ||
| Number: | rdar://26691589 | Date Originated: | 07-Jun-2016 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | 9 and above |
| Classification: | Serious Bug | Reproducible: | Always |
# Title
Auto Layout fails when UINavigationController is added as a child ViewController if `scrollViewDidScroll:` calls `topLayoutGuide`
# Description
When a UINavigationController is added as a child ViewController, the view controller in the navigation controller will experience issues with Auto Layout if it has a scroll view whose delegat's `scrollViewDidScroll:` method calls into the UIViewController's `topLayoutGuide` property.
In that situation, views with auto layout constraints set up will all have a frame with size (0,0):
```
(lldb) po [0x7fb8e99b3700 subviews]
<__NSArrayM 0x7fb8e99c1650>(
<UIScrollView: 0x7fb8ea865200; frame = (364 492; 0 0); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7fb8e99bcae0>; layer = <CALayer: 0x7fb8e999fb90>; contentOffset: {0, 0}; contentSize: {0, 0}>,
<UIView: 0x7fb8e9a01fc0; frame = (0 0; 0 0); layer = <CALayer: 0x7fb8e9a01f30>>
)
```
# Steps to Reproduce
1. Create a UIViewController containing a scrollView, with its delegate's scrollViewDidScroll method calling `topLayoutGuide` on the UIViewController
2. Create a UINavigationController with the controller created in (1) as its root
3. Add the UINavigationController from (2) as a child view controller to an existing view controller
# Expected Results
The subviews within the view of the UIViewController created in (1) should be laid out as expected, according to the Auto Layout constraints they were created with.
# Actual Results
All the subviews have size (0, 0).
# Configuration
iPad Air, iPad Mini, iPhone 6
# Version & Build
iOS 9 and above
# Sample Project
https://www.dropbox.com/s/npjq21zk7nd284h/ViewController.m?dl=0
https://www.dropbox.com/s/mhnjj3zfqird1vj/NavControllerTester.zip?dl=0
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!