Skip to content

Instantly share code, notes, and snippets.

@steipete
Last active August 29, 2015 14:10
Show Gist options
  • Save steipete/bef0b2f6065e47cd276c to your computer and use it in GitHub Desktop.
Save steipete/bef0b2f6065e47cd276c to your computer and use it in GitHub Desktop.
rdar://19096083: Merely accessing the presentationController changes program flow and breaks rotation.
ModalController *modal = [self.storyboard instantiateViewControllerWithIdentifier:NSStringFromClass(ModalController.class)];
NavigationController *navController = [[NavigationController alloc] initWithRootViewController:modal];
// The root problem is that we configure the modal presenation style as a form sheet.
// This should simply be a NOP on iPhone, but later on has other impications that lead to our bug.
navController.modalPresentationStyle = UIModalPresentationFormSheet;
// Later on in the code flow, we do some checks on the presentation controller.
// Nothing is modified, but the controller is accessed.
//
// However, merely *accessing* the presentation controller will invoke -[UIViewController _setTemporaryPresentationController:],
// creating a temporary _UIFormSheetPresentationController object which makes
// _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation: go through another code path later on.
[navController presentationController];
/* The presenter has logic to restore the modalPresentationStyle back to UIModalPresentationFullScreen
in -[UIViewController _presentViewController:withAnimationController:completion:].
This is the pseudo-code in question:
if ([var_18 _temporaryPresentationController] == 0x0) {
esi = [var_10 traitCollection];
edi = @selector(modalPresentationStyle);
if (([var_18 modalPresentationStyle] == 0x10) || ([var_18 modalPresentationStyle] == 0x2)) {
if (objc_msgSend(STK0, STK-1) == 0x1) {
[var_18 setModalPresentationStyle:0x0];
}
}
Our access to presentationController creates the temporary presentation controller, and thus changes execution flow.
The modalPresentationStyle doesn't get reset correctly and further down in the execution chain
_preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation: goes through another code chain and doesn't call
preferredInterfaceOrientationForPresentation, thus presenting the controller in portrait.
*/
[self presentViewController:navController animated:YES completion:nil];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment