Cannot use a custom presentation controller in conjunction with UIPopoverPresentationController

Originator:bryan
Number:rdar://17834499 Date Originated:7/28/2014
Status:Open Resolved:
Product:iOS SDK Product Version:8
Classification:Enhancement Reproducible:Yes
 
Summary:
I want to use a UIPopoverPresentationController, in order to display a modal view controller in a popover on iPad, but I also want to be able to use a custom presentation controller on iPhone, in order to separate presentation and transition logic as suggested in Apple's iOS 8 presentation controller WWDC session.

Steps to Reproduce:
I'm having trouble figuring out how to use a UIPopoverPresentationController but also provide custom presentation logic when my view controller is presented on a compact device.
 
I have a view controller that gets presented differently on iPhone and on iPad:
 
* iPhone: Modally, as the child of a custom container view controller, presented with a custom animation controller
* iPad: In a popover
 
I’m in the process of trying to implement this same behavior using the new UIPresentationController classes introduced in iOS 8, and seem to have already hit an unfortunate limitation.
 
It’s easy to get the popover showing up correctly on iPad, with just the following code:
 
presentedController.modalPresentationStyle = UIModalPresentationPopover;
presentedController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
presentedController.popoverPresentationController.sourceRect = button.bounds;
presentedController.popoverPresentationController.sourceView = button;
presentedController.popoverPresentationController.delegate = self;
[self presentViewController:presentedController animated:YES completion:nil];
 
On iPhone, this same controller will be presented modally, but first I need to wrap it in a custom container view controller. To do this, I implement a couple of methods from the UIPopoverPresentationControllerDelegate protocol:
 
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
    return UIModalPresentationFullScreen;
}
 
- (UIViewController *)presentationController:(UIPresentationController *)presentationController viewControllerForAdaptivePresentationStyle:(UIModalPresentationStyle)style {
    return [[CustomContainerController alloc] initWithRootViewController:presentationController.presentedViewController];
}
 
The custom container controller is animated on screen using a custom animation controller conforming to UIViewControllerAnimatedTransitioning. In iOS 7, this animation controller was also responsible for showing the dimming view.

As of iOS 8, adding the dimming view to the view hierarchy and modifying its opacity should no longer be the responsibility of the animation controller. Instead, a custom UIPresentationController subclass should take care of this. 

The same UIViewControllerTransitioningDelegate that vends our custom animation controller can also vend a custom presentation controller, providing for a cleaner separation of concerns.

Here’s the problem I’m facing: my UIViewControllerTransitioningDelegate is never asked for a custom presentation controller, presumably because it already has one – the UIPopoverPresentationController that we started with. As such, I seemingly can’t break the ”presentation” out of my custom animation controller, the way that Apple suggests we should.

Expected Results:
I would expect to be able to either:

A) Provide a custom UIPresentationController to be used in compact size classes only, even if a UIPopoverPresentationController is being used for normal size class devices.

B) Customize UIPopoverPresentationController somehow (perhaps by subclassing it?) to be able to specify what the custom presentation should be in compact mode.

Actual Results:
When using UIPopoverPresentationController, my UIViewControllerTransitioningDelegate is never asked for a custom presentation controller, presumably because it already has one.

Version:
iOS 8 SDK beta 4

Configuration:
iOS 8 simulator

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!