Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISplitViewController portrait to landscape rotation disabled in iOS 8 when popover presented

Ok, this is a weird one.

In iOS 8, if a popover is presented from the master panel in a UISplitViewController while in portrait, rotation is disabled. I've run through a bunch of tests and confirmed this is the case.

There's a private method on UISplitViewController, _shouldPreventAutorotation, that gets called when rotating and inspects the presentationController property on the popover's content controller. If this returns a non-nil value, rotation is disabled. If you override the property and return nil, rotation is once again enabled.

Does anyone have any idea why this behaviour was added in iOS 8?

I uploaded test project that demonstrates this behaviour here.

like image 304
Colin Humber Avatar asked Feb 13 '15 18:02

Colin Humber


1 Answers

So, after some more investigation and decompiling in Hopper, there's a private method on UISplitViewController that gets called when the device is rotated that determines whether or not rotation should be disabled.

If the master panel is visible, the master panel has a child modal view controller (in this case a popover), and the presented popover's presentationController property returns a non-nil value, then rotation is disabled.

I can override this behaviour by overriding -presentationController on the popover's controller, and return nil. Not sure about any side effects yet but it works.

- (UIPresentationController *)presentationController {
    return nil;
}
like image 181
Colin Humber Avatar answered Sep 27 '22 23:09

Colin Humber