I'm using a UISplitViewController and in my detail view, I am trying to use willTransitionToTraitCollection:withTransitionCoordinator:
to change the visibility of a couple views when the vertical size class changes to Compact.
On only the iPhone (not iPhone Plus or iPad) If I change the preferredDisplayMode
to UISplitViewControllerDisplayModePrimaryOverlay
, willTransitionToTraitCollection:withTransitionCoordinator:
is not called the first time the device is rotated, but willTransitionToSize:withTransitionCoordinator:
is. If I set preferredDisplayMode
to anything else it works just fine. If you rotate the device prior to selecting an item in the Master list, it works just fine. It is ONLY on the first rotation from portrait to landscape.
This is easily reproduced using the Master-Detail template:
AppDelegate:
- (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;
}
In DetailViewController
, add the viewWillTransitionToTraitCollection
and viewWillTransitionToSize
implementations and set breakpoints:
- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
You will see that willTransitionToSize:
is always called, but willTransitionToTraitCollection:
is not called for the first transition.
Does anyone know why this is? I feel like this is a bug, but I wanted to see if anyone has an explanation before I send a bug report into Apple's bug reporter black hole.
Going with "this is a bug".
I've submitted a bug report to Apple and have created a radar for it: https://openradar.appspot.com/radar?id=5015544713445376