Search code examples
iosios8uipopovercontrolleruitraitcollection

iOS8 change UIPopoverPresentationController trait collection


I'm deploying an application on both iphone and ipad (iOS7 and iOS8).
I'm using storyboard with size classes, basically I have a base size classes Any-Any that fits iPad layout and a Compact-Regular that fits all iphone models.
Some view controllers in the iPad version are presented with a custom slide in/out segue, others with popovers.
While it works perfectly on iOS7 ipad (since xcode build different storyboards) on iOS8 I have the problem that what is shown in the popover picks the iphone interface.
I present it in the usual way:

if (UIPopoverPresentationController.self) {
                    commentVC.modalPresentationStyle = UIModalPresentationPopover;
                    UIPopoverPresentationController * presentationController = commentVC.popoverPresentationController;
                    presentationController.sourceRect = [[(AFPostTimelineTableViewCell*)cell commentButton] frame];
                    presentationController.sourceView = cell;
                    presentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
                    presentationController.delegate = weakSelf;
                    weakSelf.myPop = presentationController;
                    [weakSelf presentViewController:commentVC animated:YES completion:NULL];
                }

Checking the code I've seen that the presented view controller has a UITraitCollection of C-R.
Is there a way to make it pick the R-R?
Here is also a little sample


Solution

  • Solution found, there is property in UIPresentationController that can set the UITraitCollection used on the presented -overrideTraitCollection

    presentationController.overrideTraitCollection= combinedTraits.copy;