willTransitionToTraitCollection not called on first change when UISplitViewController preferredDisplayMode is Overlay

Originator:jordanbondo
Number:rdar://28528503 Date Originated:28-Sept-2016
Status:Open Resolved:
Product:iOS SDK Product Version:
Classification:Other Bug Reproducible:Always
 
Summary:
When using a UISplitViewController on a standard iPhone (not iPhone Plus or iPad), `willTransitionToTraitCollection:withTransitionCoordinator` in the detail view controller is not called on the first orientation change of `preferredDisplayMode` is set to `UISplitViewControllerDisplayModePrimaryOverlay`

Steps to Reproduce:
Use the included example program, or perform the following steps:

1. Create a new Xcode project using the "Master-Detail Application" template.
2. In `[AppDelegate application:didFinishLaunchingWithOptions]`, after the reference to the `UISplitViewController` is obtained from `self.window.rootViewController`, set the `preferredDisplayMode` to UISplitViewControllerDisplayModePrimaryOverlay`:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;

    // ******** Add this ********
    [splitViewController setPreferredDisplayMode:UISplitViewControllerDisplayModePrimaryOverlay];

    UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
    navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem;
    splitViewController.delegate = self;
    return YES;
}

3. In `DetailViewController`, implement both `willTransitionToTraitCollection:withTransitionCoordinator` and `viewWillTransitionToSize:withTransitionCoordinator` and add NSLog statements to track how many times they are called:

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    [super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
    static int called = 0;
    called++;
    NSLog(@"willTransitionToTraitCollection call count: %d", called);
}


- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    static int called = 0;
    called++;
    NSLog(@"viewWillTransitionToSize call count: %d", called);
}

4. Build & run the application - Do not change the device orientation
5. Add a new item to the Master
6. Select the newly created item to presen the detail view for it.
7. Once the detail view is visible, change the device orientation
8. Notice that `viewWillTransitionToSize` displays a call count of 1, while `willTransitionToTraitCollection` does not print a log message.
9. Rotate the device again
10. Notice that `viewWillTransitionToSize` displays a call count of 2, while `willTransitionToTraitCollection` displays a call count of only 1.

Expected Results:
willTransitionToTraitCollection:withTransitionCoordinator should be called on every orientation change.

Actual Results:
willTransitionToTraitCollection:withTransitionCoordinator is NOT called on the first orientation change. It IS called on all subsequent orientation changes.

Version:
Xcode 7.1
Xcode 8.0
macOS 10.11.6
macOS 10.12

Notes:


Configuration:
This occurs on all 3.5", 4", and 4.7" 32 and 64-bit iPhone devices and simulators running all versions of iOS from 8.1 - 10.0.

It does NOT occur on iPad or iPhone Plus.

Attachments:
'DisplayModePrimaryOverlayBug.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!